Multiple choice technology programming languages

Which of the following class among these are synchronized?

  1. StringBuilder

  2. StringBuffer

  3. Both (1) and (2)

  4. None of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

StringBuffer is synchronized (thread-safe) while StringBuilder is not. StringBuffer's methods are synchronized, making it safe for use in multi-threaded environments, though slower than StringBuilder. StringBuilder was introduced in Java 5 as a non-synchronized alternative for single-threaded contexts.