File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes can this be called mutable? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "can this be called mutable?" Watch "can this be called mutable?" New topic
Author

can this be called mutable?

Tianpeng Xia
Greenhorn

Joined: Feb 07, 2012
Posts: 13

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

Joined: Feb 07, 2012
Posts: 13
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
Ranch Hand

Joined: Nov 09, 2011
Posts: 344
Tianpeng

You aren't changing the value of the original String. Any modification creates a new instance.
 
 
subject: can this be called mutable?
 
Threads others viewed
Creating an autogenerate number in java
aString;equals(bString) on null-object
HashSet
Stack Help...
JNI problem, pasing String to native (C function) by reference
IntelliJ Java IDE