java - Is string Object Created in Heap if we use new String("abcd") -
this question has answer here:
- how compare strings in java? 23 answers
string s1 = new string("anil"); string s2 = s1.touppercase(); string s3 = s1.tolowercase(); system.out.println(s1 == s2); system.out.println(s1 == s3);
if string object created in heap both false.but gives false,true.
string s1 = new string("anil");
this statement creates new object
and ,
string s3 = s1.tolowercase();
points location of 1st object s1
and thats reason getting true
second condition
also see how java handles strings clear understanding
hope helps!!
Comments
Post a Comment