aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes toString() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: toString()
 
Similar Threads
toString( ) method
* Byte == comparision
Interesting Question
comparison
strange results