Which on is best string or string buffer?which one is mutable and immutable?

Showing Answers 1 - 16 of 16 Answers

surendran

  • Jun 10th, 2006
 

String types are immutable and String buffer are mutable.

  Was this answer useful?  Yes

raghu

  • Jun 12th, 2006
 

Strings are not dynamically growable but String buffer is dynamically growable.

  Was this answer useful?  Yes

venkat lankal

  • Jun 15th, 2006
 

while peforming +

String is effecient rather than string buffer.

when u perform + on string buffer objects it takes more time because

it will perform append and finally it will convert sb to string

  Was this answer useful?  Yes

seyad

  • Jun 20th, 2006
 

Hi,I feel the opposite to venkat.When you have append operation to be done frequently it is advisable to use StringBuffer than String object because while you append a string with String object a new object will be created since they are immutable.ThanksSeyad

  Was this answer useful?  Yes

StringBuffer have synchronized?methods. String?have?? unsynchronized?methods.
So?String is faster?than?StringBuffer.
String?is immutable. But StringBuffer?is mutable.

So?disadvantage of?String? is memory?wastage.

If?we need synchronized?methods?and have more?memory?in?our?application then?StringBuffer?is best.
If?we?need unsynchronized?and have less memory, then String?is best.

Amit Patil

  • Sep 19th, 2007
 

Strings are immutable where as StringBuffer is mutable.
Strings cannot be modifed.That means the operations performed do not change the original object

String a="p";

a=a+a;//Statement 2:

here statement 2 creates a new object not modifying the initial object

StringBuffers can be modified:

StringBuffer a="p"

a=a.append(a);

this will modify initial string bufer

StringBuffer are syncronoized however strangely they are faster than strings

  Was this answer useful?  Yes

aarbee

  • Nov 28th, 2007
 

> StringBuffer have synchronized methods. String have   unsynchronized methods.

So one can use StringBuilder in Java 1.5

  Was this answer useful?  Yes

sampra

  • Feb 14th, 2008
 

String types are immutable and String buffer are mutable.
StringBuffer have synchronized methods. String have   unsynchronized.
We cant say best any one its depnd on situation

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions