java - Is string Object Created in Heap if we use new String("abcd") -


this question has answer here:

    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

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -