java - Why 'if' statement is giving false result on comparing two indexes of arraylist even they have same value -
this question has answer here:
- weird integer boxing in java 9 answers
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
Post a Comment