String is a immutable objects . it means that string does
not change...........
But it will be chang.........
{
String s="kapil";
String s1="raj";
String s=s1;
then print(.......)
The String has been changed ..
how it is possible and why its called immutable objects

Answer Posted / christine

Immutable means if you apply any methods to a String, it
would not affect the original String you created.
For eg,

String s = "test";
s.concat(" two");
System.out.println(s);

The output is still "test" and not "test two";
Java pass by reference. If you use = to assign the string
to another string, then the reference would change.
Therefore your example changes the string.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to handle a web browser resize operation?

537


When will you define a method as static?

549


What is the collections api in java programming?

546


Is it possible to write a regular expression to check if string is a number?

538


What is the difference between an array and an array list?

498






Garbage collection in java?

586


Is it necessary for the port addresses to be unique? Explain with reason.

570


Does collectionutils isempty check for null?

807


design an lru cache in java?

540


What is pangram in java?

507


Why singleton is not thread safe?

561


Difference between linkedlist and arraylist.

585


What are examples of modifiers?

506


What is string and example?

551


What is the properties class?

554