wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes toString Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "toString" Watch "toString" New topic


Akhil Maharaj
Ranch Hand

Joined: Sep 29, 2007
Posts: 63
Can anybody explain the reason for the following out put ?

Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
The Byte.toString() method returns a new String instance each time you call it. As a result, the expression "(b1.toString() == b1.toString())" actually creates two objects and compares their references, which will of course not be equal. However, "b1.toString().equals(b1.toString())" will evaluate to true, since both String objects contain the text "12".
[ October 29, 2007: Message edited by: Kelvin Lim ]

SCJP 5.0
I agree. Here's the link: http://aspose.com/file-tools
subject: toString
Similar Threads
* Byte == comparision
Please explain this output
related to "=="
Why is " == " on different strings with same content is returning "false"