Possible Duplicate:
Integer wrapper objects share the same instances only within the value 127?
public class test
{
public static void main(String args[])
{
Integer a1=127;
Integer a2=127;
System.out.println(a1==a2); //output: true
Integer b1=128;
Integer b2=128;
System.out.println(b1==b2); //output: false
Long c1=127L;
Long c2=127L;
System.out.println(c1==c2); // output: true
Long d1=128L;
Long d2=128L;
System.out.println(d1==d2); //output: false
}
}
Output:
true false true false
You can use negetive values too. When you observe the outputs with the values, they behave differently. What can be the reason for such different results?
For any number the range should be -127 to +127, then ==
is true or it is false.
(All) Guys sorry it was a typo error, by mistake i put it as primitive, but it's abstract. sorry for the mistake. Now corrected...