Difference between String & StringBuffer

Answers were Sorted based on User's Feedback

Answer / niranjanravi

String objects are constants and immutable where as
StringBuffer objects are not.StringBuffer Class supports
growable and modifiable string where as String class
supports constant strings. Strings once created we cant
modify them. Any such attempt will lead to the creation of
new strings.Where as StingBuffer objects after creation
also can be able to delete oo append any characteres to
it.String values are resolved at run time where as
StringBuffer valuesc are resolved at compile time.So if you
know the exact size of the string to be appended it is
better to go for String objects.

Is This Answer Correct ?    194 Yes 19 No

Answer / ramanareddy333

strings are immutable where as string buffer is a
mutable,that means strings having the fixed size and string
buffer size is varied(growable).

Is This Answer Correct ?    119 Yes 16 No

Answer / navneet raushan

The great difference between String and string buffeer is
that String buffer is thread safe where as String is not
thread safe as well as string is immutable and String
buffewr is mutable.

Is This Answer Correct ?    76 Yes 12 No

Answer / vijayakumar chinnasamy

String :
1.Content does not change –immutable

2.final class (cant subclass)

3.compareTo() - compare the string
result : < , > , = --- dictionary order

4.reverse() not available

5.is not thread safe

Criteria to choose among String
If your text is not going to change use a string Class
because a String object is immutable.


1. Content can be change Mutable

2.Final class.

3. compareTo() Not available

4.reverse() available

Allocates room for 16-addition character space when no
specific length is specified.

5.is thread safe

Criteria to choose StringBuffer

If your text can changes, and will be accessed from
multiple threads, use a StringBuffer because StringBuffer is

Is This Answer Correct ?    52 Yes 9 No

Answer / nilesh bhil( mca) amravati

String is immutable.
It means that we cant change the content of String once created. If we try append a new string using + operator
then it creates new String object.
string s = new String("Java");
s = s + "bean" ;// this statement creates new object.
String class does not have method that append new String to old String in object.

where as StringBuffer class is mutable. It means that we can add new String to it using append() method.
StringBuffer sb = new StringBuffer("Java");

Is This Answer Correct ?    38 Yes 3 No

Answer / ravikiran(aptech mumbai)

String is immutable where as StringBuffer is mutable.Means
until the newly created string object is reffered by a
reference variable it's value is uncahangable

Is This Answer Correct ?    34 Yes 7 No

Answer / bubun

string is slower in case of concatenation but stringBuffer
is faster than string.

Is This Answer Correct ?    23 Yes 2 No

Answer / devang bhagdev

in string class that is synchronized is not allows and i stringbuffer class synchronized is allows us

Is This Answer Correct ?    17 Yes 3 No

Answer / kunal chwala

It means that we cant change the content of String once created. If we try append a new string using + operator
then it creates new String object.

Is This Answer Correct ?    13 Yes 5 No

Answer / tamanna reshmi

The main difference of string class and StringBuffer is
that....while STRING class creates strings
fixed_length,STRINGBUFFER creates strings of flexible length
that can be modified in terms of both length and

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More Core Java Interview Questions

Is it possible to write method inside method

4 Answers   L&T,

Explain the difference between getAppletInfo and getParameterInfo?

1 Answers  

Why are inner classes required?

3 Answers   Oracle,

what is associative array

1 Answers   Tech Mentro,

How the elements are organized in BorderLayout?

5 Answers  

why java does not contain pointers?

13 Answers   TCS, Infosys,

java is pure object-oriented programming language?why it is platform independent.

1 Answers  

Create a form of user Login in JSP, that accepts the user name and password from user and authenticate it with user names and passwords stored in database. (Plz provide me answer immediately)

1 Answers   ABC,

what is polymorhism what is inheritance? what is Abstract n Interface? what if two interfaces have same method and a concrete class is implementing both the interfaces. Will there be a compilation error? What are mutable and immutable classes? How can u make a class mutable? when will u use dem ...explain with example? what is overriding and overloading? what is garbage collection? what is Thread? how do dey communicate? what are the different ways of implementing ? have u used any messaging technologies? what is synchronization? what are some additions in java 1.5? what are generics? whst is advanced for loop? what is finally block? can u have a try in finally? yes!! can u have a finally in finally? how do you write junits? when is a object eligible for garbage collection?explain? a = null and b has ref to a will b be eligible to be garbage collected? sql questions like diff joins? how do dey work? exception handling? what is marker interface? what is the need??

0 Answers   JPMorgan Chase,

what is difference between method overloading & method overridding with example?

4 Answers   IBM,

How does synchronized modifier work?

1 Answers   IBM,

what is tempplate pattern

4 Answers   RBS, IBM,