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().
Answer checked How we write and check questions
Discussion