0
public class AbCd {

    public static void main(String[] args)  {
        Integer i1 = 128;
         Integer i2 = 128;
         System.out.println(i1 == i2);
         Integer i3 = 127;
         Integer i4 = 127;
         System.out.println(i3 == i4);
    }
}

Here in i1==i2(128==128) we are getting false even we have the same num value, but in case of 13==14 we are getting true..what is happening internally

jww
  • 97,681
  • 90
  • 411
  • 885
  • 1
    You need to understand the different to a reference (to a point in memory) and the value that that reference contains – MadProgrammer May 11 '15 at 06:01
  • 1
    Possible Duplicate : http://stackoverflow.com/questions/1700081/why-does-128-128-return-false-but-127-127-return-true-in-this-code – Vinayak Pingale May 11 '15 at 06:01
  • @JonSkeet: Can you add [this question](http://stackoverflow.com/questions/1700081/why-does-128-128-return-false-but-127-127-return-true-in-this-code) to the above list of duplicates, please? Since it matches this question perfectly, it should be there and not "hidden" in the comments. Thank you. – Tom May 11 '15 at 06:11
  • In simple terms this is tbe same problem with comparing strings with == instead of `.equals` – Richard Tingle May 11 '15 at 06:12
  • @Tom: No, I can't. I don't get to edit that bit of the post. The simplest option would be to delete this post, to be honest - I don't think it's adding anything... – Jon Skeet May 11 '15 at 06:14

0 Answers0