Because when you do! = Comparing with an object, it compares links. And the links between the two objects are generally different.
When you compare ints, it always compares primitives, say, not links (no objects), but values.
So, if you want to work with Integer, you should use equals () for them.
Also, if your values ββare between 0 and 255, a comparison between Integer works fine due to caching.
You can read here: http://download.oracle.com/javase/tutorial/java/data/numberclasses.html
Vladimir Ivanov
source share