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


Please Help Members By Posting Answers For Below Questions

What do you mean Abstraction in java?

602


What does \ mean in regex?

617


What is balanced tree in java?

524


What is printwriter in java?

505


How big is a gigabyte?

610






What is the difference between interface & abstract class?

553


Can we catch more than one exception in a single catch block?

621


Can we sort a map in java?

571


Can we have multiple catch block for a try block?

582


What is the difference between processes and threads?

529


What is return null in java?

504


What is console based application in java?

534


What do you understand by the term polymorphism?

623


Difference between method overloading and method overriding in java ?

558


Explain method local inner classes ?

587