I have worked with String, StringBuilder and StringBuffer in java.
I thought of this question, while I was thinking from efficiency point of view.
Does “+” use in String concatenation affect efficiency?
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.
Yes, but so little it shouldn’t matter most of the time.
Using ‘+’ for string constants is the most efficient as the compiler can perform the concatenation.
If you are joining two Strings, the
concatmethod is the most efficient as it avoids using a StringBuilder.There is almost never a good reason to use StringBuffer except for backward compatibility. StringBuilder or StringWriter are a better choice. However, it is still used explicitly more often than StringBuilder in the JDK 😛
StringBuffer is dead, long live StringBuffer