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

Write a program to reverse array in place?

1068


What’s the difference between unit, integration and functional testing?

1108


Does java support function overloading, pointers, structures, unions or linked lists?

1105


Can a java program have 2 main methods?

1048


How java uses the string and stringbuffer classes?

1072


Explain about public and private access specifiers?

1055


Compare overloading and overriding?

1005


Is an integer an object?

965


How do you stop a thread in java?

1059


What is java instanceof operator?

1043


What is the advantage of OOP in java?

1149


How do you convert boolean to boolean?

1158


What is sortedmap interface?

997


Do you know why doesn't the java library use a randomized version of quicksort?

953


What is difference between overloading and overriding in java?

1027