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
How will you add panel to a frame?
What is the purpose of the wait(), notify(), and notifyall() methods in java programming?
What is string made of?
Will the jvm load the package twice at runtime?
What does a za z0 9 mean?
What is return used for in java?
What is the purpose of nested class in java?
How can we break singleton in java?
What is the difference between multitasking and multithreading in Java
What is widening and narrowing in java? Discuss with an example.
What is logical variable?
How many ways can we create singleton class?
What do you mean by Function Overloading in java?
Garbage collection in java?
How do I stop concurrentmodificationexception?