According to the source of String, if there is white space in the String that you call trim on, it will return the output of the substring method. The substring method creates a new String unless the parameters to it are 0 and the length of the String.
posted 13 years ago
thanks for reply but i do not get exactly wat u want to say so please make it more clear
Answers 1. the code will compile an print "Equal". 2. the code will compile an print "Not Equal". 3. the code will cause a compiler error
The answer is 2. When you compare two string objects with a "==", thats means you are comparing the object references. and definitely they are not equal. the answer would have been 1, if the condition was if(" String ".trim().equals("String"))