What is the output?
Integer a = 127, b = 127; Integer c = 128, d = 128; System.out.println((a == b) + " " + (c == d));
- true true
- false false
- false true
- true false
Autoboxing caches Integer values from -128 to 127, so == compares the same object only for 127.
Play Problem Solving ▸