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
How to handle a web browser resize operation?
When will you define a method as static?
What is the collections api in java programming?
Is it possible to write a regular expression to check if string is a number?
What is the difference between an array and an array list?
Garbage collection in java?
Is it necessary for the port addresses to be unique? Explain with reason.
Does collectionutils isempty check for null?
design an lru cache in java?
What is pangram in java?
Why singleton is not thread safe?
Difference between linkedlist and arraylist.
What are examples of modifiers?
What is string and example?
What is the properties class?