File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "("String".toString() == "String")???" Watch "("String".toString() == "String")???" New topic

("String".toString() == "String")???

wei liu
Ranch Hand

Joined: Dec 06, 2001
Posts: 56
Question 121)
Read this piece of code carefully
if("String".toString() == "String")
System.out.println("Not Equal");

the code will compile an print "Equal".
the code will compile an print "Not Equal".
the code will cause a compiler error.
the ans is the first one.why? Could anyone give me a clear idea?
esp.("String".toString() == "String")
wei liu
Ranch Hand

Joined: Dec 06, 2001
Posts: 56
This object (which is already a string!) is itself returned.
i know the explanation!
I agree. Here's the link:
subject: ("String".toString() == "String")???
Similar Threads
I need help with Strings
'==' operator on String objects
String Class
Please Answer soon with explanation
String literals