A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Confusion about string objects
Joined: Oct 17, 2010
Feb 23, 2011 19:00:05
Can anyone explain the meaning that
objects is immutable?
I Hear I Forget, I See I Remember, I Do I Understand.
clojure forum advocate
Joined: Nov 08, 2003
Feb 23, 2011 19:05:34
Basically it means that once you created a String, you can't change it (one of its characters for example).
Any operation like swapping a character, upper casing it and others is going to create a new String.
Joined: Oct 27, 2005
Feb 24, 2011 00:31:52
Note that you can't change the String object, but changing the String reference is possible (if the variable isn't final):
String s1 = "Hello World"; String s2 = s1; // both refer to the same "Hello World" object s2 = s2.substring(0, 5); // s2 is the new "Hello" String, s1 is still the original "Hello World" String
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
Joined: Dec 06, 2010
Feb 24, 2011 02:35:17
Hi Roger, you can see the source code of String API methods to research more on this topic....
It will give you more knowledge and confidence on this popular question...
I agree. Here's the link:
subject: Confusion about string objects
No. of String Objects
number of objects created?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015