Please tell me a real time situation to compare String, StringBuffer, and StringBuilder?
Please tell me a real time situation to compare String , StringBuffer , and
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Mutability Difference:
Stringis immutable, if you try to alter their values, another object gets created, whereasStringBufferandStringBuilderare mutable so they can change their values.Thread-Safety Difference:
The difference between
StringBufferandStringBuilderis thatStringBufferis thread-safe. So when the application needs to be run only in a single thread then it is better to useStringBuilder.StringBuilderis more efficient thanStringBuffer.Situations:
Stringobject is immutable.StringBuilderis good enough.StringBufferbecauseStringBufferis synchronous so you have thread-safety.