Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

toString()

 
Thiru Thangavelu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
output true for equals(), Obviously since Boolean wrapper class overrides equals().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic