What is the differnence between String Buffer and String
builder despite having knowledge that String builder is
faster than String Buffer and last one is threadsafe.please
tell another important difference.

Answers were Sorted based on User's Feedback



What is the differnence between String Buffer and String builder despite having knowledge that St..

Answer / rinaldoshi kalol

String is immutable whereas StringBuffer and StringBuilder
can change their values.

The only difference between StringBuffer and StringBuilder
is that StringBuilder is unsynchronized whereas
StringBuffer is synchronized. So when the application needs
to be run only in a single thread then it is better to use
StringBuilder. StringBuilder is more efficient than
StringBuffer.

Criteria to choose among String, StringBuffer and
StringBuilder

If your text is not going to change use a string Class
because a String object is immutable.
If your text can change and will only be accessed from a
single thread, use a StringBuilder because StringBuilder is
unsynchronized.
If your text can changes, and will be accessed from
multiple threads, use a StringBuffer because StringBuffer
is synchronous.

Is This Answer Correct ?    16 Yes 1 No

What is the differnence between String Buffer and String builder despite having knowledge that St..

Answer / sanjay

WHEN AN APPLICATION NEEDS TO BE RUN ONLY BY SINGLE THREAD
IT IS BETTER TO USE STRING BUILDER BECAUSE IT IS
UNSYNCHRONIZED

WHEN AN APPLICATION NEEDS TO BE RUN BY MULTIPLE THREADS IT
IS BETTER TO USE STRING BUFFER BECAUSE IT IS SYNCHRONIZED

Is This Answer Correct ?    9 Yes 3 No

What is the differnence between String Buffer and String builder despite having knowledge that St..

Answer / vinodkumar uttara student

StringBuilder all methods are not synchronized , nothing
changes done in this class , it is same as StringBuffer.I
mean to say , more than one thread can be execute
StringBuilder object , because there is not a concept of
lock on object , any thread can execute on this object.Where
as StringBuffer class all methods are synchronized only one
thread at time can access synchronized method , because it
get lock on object.

Please help me , if i am right?
is it correct,
thanks for the reply

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More Core Java Interview Questions

What is the difference between a vector & an array list?

0 Answers   Agilent,


What is Distributed Application and what is its usage?

2 Answers  


Is hashset ordered?

0 Answers  


What is public static void main?

0 Answers  


What are the 3 types of control structures?

0 Answers  






what ide u r using and wat version, how wil u build the project etc ?

2 Answers  


What is an interface in java?

0 Answers  


What is the best way to findout the time/memory consuming process?

0 Answers  


What is left shift and right shift?

1 Answers  


There is a Banking application. It has 2 types of account, Savings and Current. Write a method calculateInterest by passing an ArrayList of these account objects and calculate Interest accordingly. Write code for this situation

1 Answers   ABC, KPIT,


Can you explain the difference b/n abtract and interface with a good example,?In what cases we have use abtract and what case interface?

4 Answers   Satyam,


What is keyword auto for?

0 Answers  


Categories