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

My HTML document is not linking to my CSS stylesheet properly -

php array slice every 2th rule -

node.js - Sending sockets to client side, Error: Converting circular structure to JSON -