This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Byte and String 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 "Byte and String" Watch "Byte and String" New topic

Byte and String

Mylene Morato

Joined: Feb 10, 2009
Posts: 10

Hello friends,

I have this code:

The output is false

Could anybod help me ?
Why the output is false?


Henry Wong

Joined: Sep 28, 2004
Posts: 18545

Could anybod help me ?
Why the output is false?

Well, simply, the toString() method generates a new string every time. The value in the strings are the same, but they are different strings. And since you are only checking the references, it is false.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ken Truitt
Ranch Hand

Joined: Aug 23, 2007
Posts: 124
b1.toString().equals(b1.toString()) would be true, in other words

SCJP 88% | SCWCD 84%
I agree. Here's the link:
subject: Byte and String
Similar Threads
why the outputis false....
toString() behaviour?
Byte class(Wrapper class)
Understanding Byte and == Op