• Post Reply Bookmark Topic Watch Topic
  • New Topic

can this be called mutable?  RSS feed

 
Tianpeng Xia
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Above is my code. i just want to see if String is relally immutable. if the aString is immutable, how can i change the valuel of it ? by the way, the two outputs are both true.
MUCH THANKS

 
Tianpeng Xia
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I reconize where the point is !!

the replace method didn't change the real value inside aString, it just appeared like that... when i added a new line " System.out.println(aString);", the output is "hello.world!"
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tianpeng

You aren't changing the value of the original String. Any modification creates a new instance.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!