When you say String is immutable, what do you mean by that?
Say I have String s = "Ness"
s= s+"Technologies";
What will happen? If the value gets appended, then what is
the meaning of immutable here?
Answer Posted / haribabu
Once you have assigned a value to a "String Object" (i am
saying an "object" not the "object reference")that value
can never change. This is immutability.
by defining "s = s+Technologies" we are pointing the
REFERENCE to newly created "string object" with the
modified string. So the previous string object is
considered to be lost.
This concept has explained very well in String, I/Os
chapter of Kethy Siera, SCJP 5.
All the best
| Is This Answer Correct ? | 26 Yes | 0 No |
Post New Answer View All Answers
What is dynamic binding(late binding)?
Why do we need autoboxing in java?
What is the use of a conditional inclusion statement in Java ?
Is array an object in java?
Can we serialize static variables in java?
What is update method called?
Why do we need variables?
What is valid keyword in java?
What is tostring () method?
How does list work in java?
When should I use singleton?
Name the components that are termed to be Heavy-weight component but available in Light-weight components?
What is a “stateless” protocol ?
Describe method overriding
What is hashing principle in java?