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 a arraylist in java?

1004


What is static and final keyword in java?

984


Can you sort a string in java?

859


What are the drawbacks for singleton class?

953


What is ternary operator in java?

1020


What do you understand by private, protected and public?

1003


how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? : Java thread

962


Is this valid in java ? Can we instantiate interface in java?

932


Can we call virtual funciton in a constructor ?

2142


Can size_t be negative?

1084


What is application tier?

1054


Explain throw keyword in java?

996


Program to Find the second largest element in an array.

1119


How to make a read-only class in java?

1085


What is the do while loop syntax?

988