java - Why 'if' statement is giving false result on comparing two indexes of arraylist even they have same value -


this question has answer here:

today found strange thing arraylist. following program:

    arraylist<integer> al = new arraylist<integer>();     al.add(128);     al.add(128);     int t1 = al.get(0);     int t2 = al.get(1);     if(al.get(0)== al.get(1))       system.out.print("true");     else       system.out.print("false");     if(t1== t2)       system.out.print("true");     else       system.out.print("false"); 

it giving result falsetrue. value less 128, giving truetrue. don't understand logic behind it?

the java language specification says wrapper objects @ least -128 127 cached , reused.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -