File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Confusion about string objects" Watch "Confusion about string objects" New topic

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

Joined: Nov 08, 2003
Posts: 3479

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

Joined: Oct 27, 2005
Posts: 20279

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

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:
subject: Confusion about string objects
It's not a secret anymore!