What is the difference between String and StringBuffer?

Questions by ramesh_etta

Showing Answers 1 - 33 of 33 Answers

Srikanth Rao

  • Nov 13th, 2006
 

1.String Class is inMutable, and StringBuffer is Mutable

2.String Class Don't have append Method

kishan

  • Nov 16th, 2006
 

1)string and string buffer both implements charecter sequence interface,but strings r immutable and string buffers r mutable

2)string buffers works fast for concatenation operations bcz it has append method init

  Was this answer useful?  Yes

rajendra babu

  • Nov 17th, 2006
 

The main diff. b/w string and stringbuffer is

string is immutable(cannot change the content)

stringbuffer is mutable(can change the content)

  Was this answer useful?  Yes

chinnu

  • Nov 18th, 2006
 

strings and string buffer classes are final classes in java.string buffer s have some data manipulation methods are available .in strings are not.string buffer is faster than the string.string s are immutable objects (contents of the objects cant be modified)string buffere s are mutable objects(contents of the objects can be modifies).bbye cheerschinnu

  Was this answer useful?  Yes

Avitra

  • Nov 23rd, 2006
 

String                                           StringBuffer

not sychronized                     Synchronized

Immutable                             mutable

  Was this answer useful?  Yes

Guest

  • Nov 29th, 2006
 

String StringBuffer1) String is immutable. 1)StringBuffer is muatable.2)String is Synchronised

  Was this answer useful?  Yes

string is an class and its objects are constt.String Buffer is anotehr class and is  better than string  since it saves time and memory. String buffer includes all functions of string class ,also it has one more fn,i.e sb.reverse();
String objects are constt ,what it means is that the CONTENTS OF String instance cannot b changed after it has been created.This is not with StringBuffer instance.
bye

  Was this answer useful?  Yes

bihag

  • Jan 11th, 2007
 

1.String is immutable               --  StringBuffer is not.

2. String is not threadsafe        -- StringBuffer is thread safe

3. String has concat() for append character   -- StringBuffer has append() method

4. while you create String like, String str = new String(); --> it create 2 object 1 on heap and 1 on "String Constant pool" and that refered by str               --- That's not in StringBuffer , it Create 1 object on heap

5. String is most commanly use in java applications     ---- Mostly used in I/O functions.

-----------------------------------------------------------------------------------------------------------

As for Java 5 new class was added -- StringBuilder , that has same functionlity as StringBuffer but it is not thread safe.

-----------------------------------------------------------------------------------------------------------

Simmilarity is that .... Both are final class

  Was this answer useful?  Yes

paddu

  • Oct 12th, 2007
 

Strings are immutable that means we cann't change the content or data. Where in the case of StringBuffer we can change the data or content that are presented in that.

  Was this answer useful?  Yes

sampra

  • Feb 22nd, 2008
 

One majar diff also is string obj are immutable where as string buffer objects are mutable  

  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