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 / akhil saxena

Immutable means which cant not be changed. whenever you call
a method though an instance of String class it will give you
the result as new String object. It wont change the existing
String object.

String class objects are made immutable so that if the
String is logically same,then more than one object can refer
the same single String in memory. in this way it also saves
memory.

Example: String a="ABC";
String b="ABC";

in above example JVM will create only one object with the
value "ABC" and both the reference variables a and b will
refer to the same. So it is saving memory.


If you need to change a String object very frequently, it is
not adviced to use a String object as it creates a new
object whenever you change its value. Its a best practice to
use StringBuffer. it is mutable.

For more info write to me at akhilsaxenain2000@yahoo.com

Is This Answer Correct ?    12 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do negative exponents mean?

964


What is a linkedhashmap java?

947


Is static variable stored in heap?

924


Explain notifyall() method of object class ?

1045


Is array primitive data type in java?

942


If try block is successfully executed, Then Is Finally block executed?

1037


Addition to previous section relative word 5th one was Putrid ans: rotten, also there was prob. in 1st section on bucket weight ans:10kg, also there was a prob. on train speed to find bridge length ans:800 mtrs.

2111


What are keyboard events?

1094


What is overriding in java?

989


Can a class have an interface?

918


What language is java written?

966


Can we call the constructor of a class more than once for an object?

1041


what do you mean by java annotations?

1050


Explain the concept of hashtables?

1058


You're given a Boolean 2D matrix, can you find the number of islands?

1046