GeekInterview.com
Series: Subject: Topic:
Question: 239 of 576

what is the difference between String and StringBuffer?

Asked by: ramesh_etta | Member Since Nov-2006 | Asked on: Nov 10th, 2006

View all questions by ramesh_etta

Showing Answers 1 - 11 of 11 Answers

 The methods in string class are not sychronized.Where as the methods of the StringBuffer class can be synchronized .

  
Login to rate this answer.
Srikanth Rao

Answered On : Nov 13th, 2006

1.String Class is inMutable, and StringBuffer is Mutable

2.String Class Don't have append Method

Yes  1 User has rated as useful.
  
Login to rate this answer.
kishan

Answered On : 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

  
Login to rate this answer.
rajendra babu

Answered On : 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)

  
Login to rate this answer.
chinnu

Answered On : 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

  
Login to rate this answer.
Avitra

Answered On : Nov 23rd, 2006

String                                           StringBuffer

not sychronized                     Synchronized

Immutable                             mutable

  
Login to rate this answer.
Guest

Answered On : Nov 29th, 2006

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

  
Login to rate this answer.

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

  
Login to rate this answer.
bihag

Answered On : 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

  
Login to rate this answer.
paddu

Answered On : 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.

  
Login to rate this answer.
sampra

Answered On : Feb 22nd, 2008

View all answers by sampra

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

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.