Multiple choice technology programming languages

For concatenation of strings, which method is good, StringBuffer or String

  1. String

  2. StringBuffer

  3. Both

  4. None

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

StringBuffer is mutable and more efficient for multiple concatenations in loops because it modifies a single buffer. String is immutable - each concatenation creates a new object. For repeated concatenation, StringBuffer (or StringBuilder in newer Java) is preferred. The claimed answer B is correct.