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
Write a program to find the whether a number is an Armstrong number or not?
When should you make a function static?
What is the purpose of the system class in java?
What is the use of default method in interface in java?
What is the full form of jpeg?
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.
What are use cases?
What is a function easy definition?
How do you use compareto in java?
How many inner classes can a class have?
What do you understand by the term singleton?
Is a class subclass of itself?
What is an accessor?
What is the right data type to represent a price in java?
Is java an open source?