I understand that int values, when autoboxed, are interned i.e no 2 objects containing the same int are present, and so we can compare two Integers by == So why does the following happen :

Integer iRef1=1000;
Integer iRef2=1000;
System.out.println(iRef1 == iRef2);
System.out.println(iRef1.equals(iRef2));

This prints

false
true

On the other hand, if I say

Integer iRef1=10;
Integer iRef2=10;
System.out.println(iRef1 == iRef2);
System.out.println(iRef1.equals(iRef2));

the output is

true
true

Why is there no interning in the second case ?

Sorry, I failed to notice that INTs are interned only when they are in the range of -128 to 127

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.