permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Strings" Watch "Strings" New topic
Author

Strings

Rajani Sudhakar
Ranch Hand

Joined: Apr 28, 2004
Posts: 60
Read this piece of code carefully

__________________________________________________________

if("String".replace('g','G') == "String".replace('g','G'))
System.out.println("Equal");
else
System.out.println("Not Equal");

___________________________________________________________
Answers

1.the code will compile an print "Equal".
2.the code will compile an print "Not Equal".
3.the code will cause a compiler error

Correct Answer : 2.the code will compile and print "Not Equal"

But the result String formed on the lefthand side and that of the righthand side seem to be equal..

Can anyone justify the correct answer?

Thanks in advance,
rajani.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Compare the output from that code with this:



Did you figure it out yet? If not, check this out, as well.


SCJP Tipline, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strings