Codes :
Integer a1 = 100;
Integer a2 = 100;
System.out.println(a1 == a2); // true
Integer b1 = new Integer(100);
Integer b2 = new Integer(100);
System.out.println(b1 == b2); // false
Integer c1 = 150;
Integer c2 = 150;
System.out.println(c1 == c2); // false
Java designs that when using AutoBoxing, values between -128 and 127 appear to refer to the same Integer objects, which causes different results of the first code fragments and the last one
My question is : Why does java design it like this, are there any advantages ?