Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Byte and String

 
Mylene Morato
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello friends,


I have this code:





The output is false

Could anybod help me ?
Why the output is false?

Thanks.
 
Henry Wong
author
Marshal
Pie
Posts: 21378
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Henry
 
Ken Truitt
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
b1.toString().equals(b1.toString()) would be true, in other words
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic