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 are the types of strings?
What is the relationship difference the canvas class and the graphics class?
What is the platform?
Do extraneous variables affect validity?
How do you clear a list in java?
What does sizeof return?
How do you change an int to a string?
What is the java project architecture?
Can we override compareto method?
How is garbage collection controlled?
How is tree Mirroring implemented?
What are static methods?
How does a cookie work in Servlets?
What is double checked locking in singleton?
What is a final class in java?