what is difference between String buffer and String builder?
Answer Posted / mohan
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 ? | 4 Yes | 0 No |
Post New Answer View All Answers
What is java algorithm?
How can we make sure main() is the last thread to finish in java program?
What is a generic data type?
Why synchronization is important in java?
What is a parameter in java?
What is a stack class in java ?
What is the association?
explain copyonwritearraylist and when do we use copyonwritearraylist?
How can you make sure that your singleton class will always return single instance in multi-threaded environment?
How are variables stored?
How do you calculate roots in java?
List two java ide’s?
Which method returns the length of a string?
Is main a function?
How to run a JAR file through command prompt?