Answer Posted / anonymous
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 ? | 26 Yes | 0 No |
Post New Answer View All Answers
what are the activation groupworks?
What is a class loader?
Why is string immutable in java?
Explain ioc concept?
difference between ejb,struts,hibernate,spring and jsp
What is difference between object state and behavior?
Difference between hashmap and hashtable?
Explain what is synchronization?
What is an abstract method?
What is a tasks priority and how is it used in scheduling?
what is handle?
What is the difference between a static and a non-static inner class?
what are getters and setters in Java with examples?
What is message driven beam?
What are the design considerations while making a choice between using interface and abstract class?