Win a copy of Kotlin in Action this week in the Kotlin forum!
    Bookmark Topic Watch Topic
  • New Topic

String object creation  RSS feed

 
Rohan Pujari
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Report post to moderator
when i write the statement

String s = new String("abc") ;

There are two string objects created right??

so in the code below how many string objects are actually created.

String s1 = "abc";
String s2 = new String("xyz");
s2=s1;
s1.toUpperCase();
String s3 = "abc" ;
String s4 = s3.replace('a','A');

well i think in all five objects are created.
please correct me if i am wrong.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't cross-post. People don't like to volunteer their time answering questions when the same question has already been answered in another forum.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!