File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Strings are immutable ? is it true or not
Joined: Mar 09, 2005
May 03, 2005 00:21:00
I know that Strings are fixed length, immutable right.
consider the following example and explain how it achieves it.
String s = "hello"; ok
when u apply toUpperCase() to the above string it gets changed to "HELLO".
THEN how are you saying it is not mutable. explain please.
Joined: Apr 26, 2005
May 03, 2005 00:39:00
Because toUpperCase returns a new String:
String upper = test.toUpperCase();
SCJP 5.0, SCWCD
Joined: Feb 03, 2004
May 03, 2005 03:55:00
in addition to Hendriks post:
After that opration, you'll have two objects in the heap.
"HELLO", referenced by s.
"hello", not referenced by any variable, ready to be garbage collected.
subject: Strings are immutable ? is it true or not
Question on immutability
Immutable String ??
Strings Immutable ?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013