In Java I have written below code for string trim() method.
if(" String ".trim() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
It gives output Not Equals which I understood because " String ".trim() had returned new String object reference .
But when I trim and compare without white spaces it gives output Equals.
if("String".trim() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
If String is not having white spaces what trim() method returns?
I know equals() I can use but in my exam I got this question.