aspose file tools*
The moose likes Beginning Java and the fly likes Confusion about string objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
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: 3476

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: 19542
    
  16

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sunny Bhandari
Ranch Hand

Joined: Dec 06, 2010
Posts: 448

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...


Java Experience
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confusion about string objects
 
Similar Threads
garbage collection
number of objects created?
containers
String Objects
No. of String Objects