Question 10
Back to Exercise
Why is s += x inside a loop slow for large loops?
- A += is not optimised by the JIT
- B Each += creates a new String and copies all previous characters, giving O(n²) total work Correct
- C Strings are stored in files
- D It uses synchronisation
Correct Answer: Option B
A StringBuilder appends into a growing buffer in amortised O(1) per append.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!