What will be the result of compilation and execution of the following code?

Integer i = new Integer("10");
if (i.toString() == i.toString())
   System.out.println("Not Equal");
Method toString() returns a String representation of an object.
Every time it is called on an object of class Integer, a new String object is created. Operator == compares two references to two String objects, and not the real values of those String objects.
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback