• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

toString

 
Akhil Maharaj
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody explain the reason for the following out put ?

 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic