As of i know any changes on String a new Object will create,and for some run time activity if there is a content change then a new object will create in Heap are, but i am confusing on below cases, please give idea...
String s8="abcd"; String s9=s8.toUpperCase(); String s11=s8.toUpperCase(); System.out.println("S9 "+s9.hashCode() +" s10 "+s11.hashCode());//S9 -- 2001986 s10 -- 2001986 System.out.println(s9==s11);//false In the above scenario the address is printing same but the == operator shaowing false.
please tell why address is same and comparision is false.
s9.hashCode()is not an address.Stringclass overrideshashCode. The value depends on the contents of theString..toUpperCase()returns a new String.==with objects compares identity (is it the exact same object), you need to use.equals()to check if they are equal (same value, but possibly different object).