Java Output Prediction Hard +35 XP
Autoboxing Trap
What does this print?
JavaRead-only
Integer a = 1000; Integer b = 1000; System.out.println(a == b); System.out.println(a.equals(b));
What is the output?
Show answer and explanation
Answer: false then true
Integer cache only covers -128 to 127. 1000 is outside, so a == b compares references (false). equals() compares values (true).
Hint: Integer cache stops at 127.
What this challenge tests
Output Prediction in Java: autoboxing, integer-cache.