-----------------------------------------------
String s1 = "hI".toUpperCase();
String s2 = "HI".toUpperCase();
String s = "HI";
System.out.println(s == s1); // Prints False
System.out.println(s == s2); // Prints True
-------------------------------------------
whenever we call upon built in method like toUpperCase, toLowercase, trim, replaceetc., it first look upon whether any changes to be done before on the given string.. if so it create new string in string pool if not available...if no need for any change then the method will return same string..
in the above program .....
String s1 = "hI".toUpperCase();
String s = "HI";
System.out.println(s == s1); // Prints False
because there is change in s1 and it going to point new string
but in this
String s2 = "HI".toUpperCase();
String s = "HI";
System.out.println(s == s2); // Prints True
its going to return same string...
check the source code of toUppercase in
java API it first checks whether there is any modification needed for string
All plz check source code of String methods...
it more helps U