Home » Java » java – Why Integer variables get these behaviour?-Exceptionshub

java – Why Integer variables get these behaviour?-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

when we define an Integer variables like below

Integer x=111; // (1)
Integer y=111; // (2)
Integer a=455; // (3)
Integer b=455; // (4)

And once we perform followings,

x==y // returns true
x.equals(y) // returns true
a==b // returns false
a.equals(b) // returns true

Can someone explain these behavior ?
Thanks in advance.

How to&Answers: