Forums Register Login

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

+Pie Number of slices to send: Send
Question 121)
Read this piece of code carefully
if("String".toString() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
Answers

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")
+Pie Number of slices to send: Send
This object (which is already a string!) is itself returned.
i know the explanation!
Die Fledermaus does not fear such a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 528 times.
Similar Threads
String literals
'==' operator on String objects
Please Answer soon with explanation
I need help with Strings
String Class
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:05:50.