This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Confusion about string objects Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Confusion about string objects" Watch "Confusion about string objects" New topic
Author

Confusion about string objects

Roger Fed
Ranch Hand

Joined: Oct 17, 2010
Posts: 82

Can anyone explain the meaning that string objects is immutable?


I Hear I Forget, I See I Remember, I Do I Understand.
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3359

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.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Note that you can't change the String object, but changing the String reference is possible (if the variable isn't final):


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Sunny Bhandari
Ranch Hand

Joined: Dec 06, 2010
Posts: 446

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: http://zeroturnaround.com/jrebel
 
subject: Confusion about string objects
 
Similar Threads
garbage collection
String Objects
number of objects created?
containers
No. of String Objects