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
Difference between final and effectively final ? Why is effectively final even required ?
Explain restrictions on using enum?
Which keyword specify that a variable is effectively final ?
What is meant by data hiding in java?
Is set sorted in java?
Why is java so important?
Explain about interrupt() method of thread class ?
What is the purpose of a transient variable?
What is the importance of main method in Java?
What is main string [] args?
how we can make a read-only class in java?
Which collection does not allow duplicates in java?
How to restrict a member of a class from inheriting by its sub classes?
What are peerless components?
What is the difference between keyword and identifier?