challange explanation | Sololearn: Learn to code for FREE!

+5

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

ABADA S

3 Answers

New Answer

+2

Additionally Hope these may help you.. https://www.sololearn.com/Discuss/1930263/?ref=app https://www.sololearn.com/Discuss/2132457/?ref=app

+1

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).

+1