Consider a scenario where a very large number of string concatenation operations are being performed in a single-threaded application. Which class would be appropriate to use for string manipulation, and why?

  • String
  • StringBuffer
  • StringBuilder
  • StringJoiner
In a single-threaded application with frequent string concatenation, StringBuilder is the most suitable choice. It's efficient because it doesn't create new objects when you modify the string, which can save memory and reduce overhead. StringBuffer is also thread-safe but slightly slower due to synchronization. String creates a new string each time you modify it, and StringJoiner is used for joining strings, not efficient for concatenation.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *