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 do you mean Abstraction in java?
What does \ mean in regex?
What is balanced tree in java?
What is printwriter in java?
How big is a gigabyte?
What is the difference between interface & abstract class?
Can we catch more than one exception in a single catch block?
Can we sort a map in java?
Can we have multiple catch block for a try block?
What is the difference between processes and threads?
What is return null in java?
What is console based application in java?
What do you understand by the term polymorphism?
Difference between method overloading and method overriding in java ?
Explain method local inner classes ?