This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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


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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Strings
 
It's not a secret anymore!