Question
In Java, which comparison about StringBuilder vs StringBuffer is accurate?
- There is no practical difference in behavior, performance, or API design when StringBuilder vs StringBuffer is involved.
- The oldest option related to StringBuilder vs StringBuffer is always the right production choice regardless of context.
- Differences around StringBuilder vs StringBuffer are mostly cosmetic, so correctness and maintainability do not change.
- StringBuilder is typically preferred in single-threaded code, while StringBuffer exists for legacy synchronized use cases.
Hint
Focus on the behavior or tradeoff, not just the keyword.
Answer and rationale
Correct answer: D. StringBuilder is typically preferred in single-threaded code, while StringBuffer exists for legacy synchronized use cases.
StringBuilder is typically preferred in single-threaded code, while StringBuffer exists for legacy synchronized use cases. This is the comparison that usually separates memorization from understanding.
Track: Java