challange explanation | Sololearn: Learn to code for FREE!


challange explanation

What is the output of this code? Integer i1 = 127; Integer i2 = 127; System.out.println(i1 == i2); i1 = 128; i2 = 128; System.out.println(i1 == i2); why the answer is true false

12/24/2020 9:45:40 PM


3 Answers

New Answer


Additionally Hope these may help you..


I remember slightly someone mentioned about value caching for Java Integer. As I recall, value of Integer from -128 up to 127 was cached in memory, and its reference is reused when another Integer was created, and assigned a value within that range (-128 ~ 127). A bit like string pool work for efficiency I guess (cmiiw).