Dinesh Kumar Kumar wrote:For String or another objects, if we create objects in the above way, it returns false.
Well, for one thing, you can't create other objects the same way (ie, with literals).
Second, primitives are NOT objects, so chances are that they will behave differently.
Third (and this is a tip) when comparing a primitive with an object - which will usually be its wrapper type - be explicit about what you want to happen.
Your (i==j) above could be interpreted in two ways:
(i == j.intValue()) or
(Integer.valueOf(i) == j) and the two comparisons are different: The first is a value comparison, the second an identity comparison, and they work very differently.
Even better still, use equals(). That way there's no possible ambiguity.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here