The problem is that you are comparing strings with ==.
Don't use == to compare strings. Use .equals(...) instead.
The == operator checks if the two references you are comparing refer to the exact same
String object. That's not the same as having two separate String objects that contain the same sequence of characters.
It is up to the implementation of class Integer, class String etc. if it wants to implement some caching mechanism, to that if you call toString() twice on the same Integer object it returns exactly the same String object twice.
You should not write programs that count on that implementation specific behaviour.
Probably class Integer has such an optimization. I haven't looked at the source code for class Integer, but it probably caches the result of toString when you call it for the first time, something like this: