Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

one more on ==

 
sachin agashe
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the output (Assuming written inside main)
String s1 = new String("amit");
System.out.println(s1.replace('m','r'));
System.out.println(s1);
String s3="arit";
String s4="arit";
String s2 = s1.replace('m','r');
System.out.println(s2==s3);
System.out.println(s3==s4);
a) arit
amit
false
true
b) arit
arit
false
true
c) amit
amit
false
true
d) arit
amit
true
true
Should it not be d)
 
akshaya bhatt
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no it is a) try by replacing == with equals and get the idea
 
sachin agashe
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the thing I suppose. Whenever you perform any method of the String class on a string, a altogether new String is created and it has nothing to do with a string existing in the string pool. So it gives false..
Thanks.
sachin.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic