Bird
0
0

Which of the following is true about StringBuilder and StringBuffer in Java?

easy📝 Conceptual Q1 of 15
Java - Strings and String Handling
Which of the following is true about StringBuilder and StringBuffer in Java?
ABoth are immutable classes.
B<code>StringBuffer</code> is synchronized, <code>StringBuilder</code> is not.
C<code>StringBuilder</code> is synchronized, <code>StringBuffer</code> is not.
DBoth classes are used to create arrays.
Step-by-Step Solution
Solution:
  1. Step 1: Understand synchronization difference

    StringBuffer methods are synchronized, making it thread-safe, while StringBuilder is not synchronized.
  2. Step 2: Check mutability and usage

    Both classes are mutable and used for building strings, not arrays.
  3. Final Answer:

    StringBuffer is synchronized, StringBuilder is not. -> Option B
  4. Quick Check:

    Synchronization = StringBuffer is synchronized, StringBuilder is not. [OK]
Quick Trick: Remember: Buffer is thread-safe, Builder is faster [OK]
Common Mistakes:
  • Confusing which class is synchronized
  • Thinking both are immutable
  • Assuming both create arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes