int vs Integer comparison Java

java

Solution

i1 == i2

results in un-boxing and a regular int comparison is done. (see first point in JLS 5.6.2)

i2 == i3 

results in reference comparsion. Remember, `i2` and `i3` are two different objects. (see JLS 15.21.3)

Problem

``` class datatype1 { public static void main(String args[]) { int i1 = 1; Integer i2 = 1; Integer i3 = new Integer(1); System.out.println("i1 == i2"+(i1==i2)); System.out.println("i1 == i3"+(i1==i3)); System.out.println("i2 == i3"+(i2==i3)); } } ``` Output ``` i1 == i2true i1 == i3true i2 == i3false ``` Can someone explain why I get false when comparing i2 and i3 ?

Original source

Related problems