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 characteristics of java?
Write a program to print fibonacci series
What is meant by call by reference?
In a container there are 5 components. I want to display all the component names, how will you do that?
Explain the term virtual machine?
Explain inner classes ?
List primitive java types?
How to disable caching on back button of the browser?
What does provide mean construction?
How to perform bubble sort in java?
What does singleton mean in java?
Can we sort set in java?
Give me example of derived data types.
What are the disadvantages of object oriented programming?
Is nan false?