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


Please Help Members By Posting Answers For Below Questions

Write a program to find the whether a number is an Armstrong number or not?

781


When should you make a function static?

728


What is the purpose of the system class in java?

767


What is the use of default method in interface in java?

767


What is the full form of jpeg?

729


Write a regular expression to validate a password. A password must start with an alphabet and followed by alphanumeric characters; its length must be in between 8 to 20.

799


What are use cases?

743


What is a function easy definition?

735


How do you use compareto in java?

743


How many inner classes can a class have?

800


What do you understand by the term singleton?

774


Is a class subclass of itself?

840


What is an accessor?

1326


What is the right data type to represent a price in java?

757


Is java an open source?

729