Practice mode Java

What is the main difference between StringBuilder and StringBuffer in Java?

Correct answer D. StringBuffer methods are synchronized, StringBuilder methods are not

Explanation

Both classes represent mutable character sequences and offer nearly identical methods. StringBuffer synchronises its operations so one instance can be shared between threads, whereas StringBuilder drops that overhead and is the recommended, usually faster, choice for use by a single thread. Neither is immutable, and each converts to a String through toString().

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.