Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

hi to all. well can you please tell me that why String class
is immutable?

Thanks in advance.

Answer Posted / mahi

Yes String cannot be modified because we can not append
another String to existing one.
Example:

1) String string=new String("abc");
2) String s2= string + "hai";

As shown in the above, 2nd line will create one new object
with the value "abchai" so it cannot be modified.

If the same thing if you do with StringBuffer class as
below we can modify

1) StringBuffer str=new StringBuffer("abc");
2) str.append("hai");
Here we can modify existing StringBuffer object - str

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why can we not override static method?

1105


Differentiate between stringbuffer and string?

1024


What is a two-pass assembler?

1053


Why is it called a string?

1011


When is the finalize() called?

1176


How to implement an arraylist in java?

1155


How many bits is a string in java?

1022


What do you mean by thread safe?

976


What 5 doubled?

986


What is entry in java?

1036


What is the final class modifier?

1039


How can constructor chaining be done using this keyword?

1276


What does main method?

979


How to do a true java ping from windows?

1158


Does java runtime require a license?

1068