Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile 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: 20892
75
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