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...

what is the main difference between string and stringbuffer?
can you explain it with program?

Answer Posted / ashish ranjan

The main difference between String and StringBuffer is that String is Immutable, which means that we cannot modify the object which is created by the String.
As for Example.
String str = "abc";
now,
str = "abc" + "pqr";
the result is abcpqr. The previous value of str is not modified. It exists in the memory. Java Created new memory for str, which refers abcpqr.

now in case of StringBuffer
StringBuffer str = new StringBuffer("abc");
str.append("pqr");
it modifies in the same object.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the size of string?

1078


What is serialization in java?

1056


Why do we need strings in java?

983


What happens if we don’t override run method ?

1000


What is busy spin, and why should you use it?

1079


What are loops in java? What are three types of loops?

1028


Is it possible to specify multiple jndi names when deploying an ejb?

985


How many types of voids are there?

971


What is the difference between import java.util.date and java .util?

1050


Difference between string, string builder, and string buffer?

1093


Why are pointers not secure?

1020


What is not object oriented programming?

931


What is data member in java?

1034


Why string is not a wrapper class?

1176


Can variables be used in java without initialization?

1070