File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes one more on == Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "one more on ==" Watch "one more on ==" New topic
Author

one more on ==

sachin agashe
Ranch Hand

Joined: Nov 08, 2000
Posts: 42
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

Joined: Dec 24, 2000
Posts: 6
no it is a) try by replacing == with equals and get the idea
sachin agashe
Ranch Hand

Joined: Nov 08, 2000
Posts: 42
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: one more on ==