Hello EveryOne,
I was just playing around the wrapper classes and observed some unexpected behaviour.
public class HelloWorld
{
public static void main(
String args[] )
{
Integer i1 = 100;
Integer i2 = 100;
System.out.println( "i1 == i2 : " + ( i1 == i2 ) );
}
}
Output of the above code is unexpected with different values of i1 and i2.
For the current values ( i1 = 100 and i2 = 100 ) the output is : "i1 == i2 : true"
But for the following code,
public class HelloWorld
{
public static void main( String args[] )
{
Integer i1 = 1000;
Integer i2 = 1000;
System.out.println( "i1 == i2 : " + ( i1 == i2 ) );
}
}
the output is "i1 == i2 : false"
From different conbinations I have observed that in the above code for values of i1 and i2 between -128 to 127 ( range of byte ), i1 == i2 evaluates to true and for other values i1 == i2 evaluates to false.
What could be the reason behind this behaviour?
Thank You,
Sanket Meghani.