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 / anil kumar khichar

Immutable means the original String never get changed or
replaced by another one. You can simply concate another one
, but beware you can't replace it. Look at the following:-


{
String s="kapil";
String s1="raj";
String s=s1;

see here if you assign s1 to s ,there will you get error.
And it's not allowed here. So we can say Strings are immutable.

Thanks!
Anil

Is This Answer Correct ?    1 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can I learn java in 3 months?

541


How to reverse a string in java?

526


Variable of the boolean type is automatically initialized as?

593


Explain about fail safe iterators in java?

567


What is a native method in java programming?

528






What is the difference between hashmap and hashtable in java?

557


What is a parameter used for?

520


Which collection allows duplicate values in java?

546


What is equals method in java?

524


Explain thread in java?

664


Can we declare array without size in java?

551


How do you add an element to a set in java?

497


Explain about core java?

626


When do I need to use reflection feature in java?

626


What does || mean in vectors?

478