juniorStrings

What is String Concatenation and its performance impact?

Updated Apr 28, 2026

Short answer

Combining strings. Repeated concatenation in a loop is O(n^2) due to constant reallocation.

Deep explanation

Strings are one of the most common data types. Combining strings. Repeated concatenation in a loop is O(n^2) due to constant reallocation. Understanding how they are represented (ASCII/UTF-8/UTF-16) is key to solving character encoding issues.

Real-world example

Storing user names or IDs in an application.

Common mistakes

  • Modifying a string inside a long loop without using a StringBuilder/StringBuffer.

Follow-up questions

  • What is the time complexity of concatenation?

More Strings interview questions

View all →