*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes toString() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "toString()" Watch "toString()" New topic
Author

toString()

Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
The answer says false. I thought since toString() is called on the sameObject, it will not create a new String. Will it again create a new String for each toString() invocation?
1: Byte b1 = new Byte("127");
2:
3: if(b1.toString() == b1.toString())
4: System.out.println("True");
5: else
6: System.out.println("False");


Thanks,<br />Thiru<br />[SCJP,SCWCD,SCBCD]
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

right... each b1.toString() method creates a new String object. but what happens if you call

if( b1.toString().equals( b1.toString() ) )
Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
Thanks,
output true for equals(), Obviously since Boolean wrapper class overrides equals().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: toString()
 
Similar Threads
Interesting Question
comparison
* Byte == comparision
toString( ) method
strange results