File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrapper-Method-Q

 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


why b1.toString() == b2.toString() is evaluating to false.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why b1.toString() == b2.toString() is evaluating to false.


When a Java expression creates a new String at run time, a new object is created. The = operator checks whether these are the same object. The equals() method would compare the characters in these objects and yield true.

"127" == "127" would be true because the String object "127" is created once at compile time in the String Literal Pool, so you are comparing an object to itself. When you use toString() to create a String, you get a unique object every time.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic