Intermediate Java
Q98 / 100

What is the difference between String.format() and StringBuilder for repeated concatenation?

Correct! Well done.

Incorrect.

The correct answer is B) StringBuilder is faster for repeated concatenation because it avoids creating intermediate String objects

B

Correct Answer

StringBuilder is faster for repeated concatenation because it avoids creating intermediate String objects

Explanation

Concatenating with + in a loop creates O(n^2) String objects. StringBuilder.append() is O(n). String.format() is convenient but allocates more than direct StringBuilder use.

Progress
98/100