Skip to content
Home

Concatenation: joining strings and sequences in language, math, and computing

Concatenation is the operation of joining two or more strings or sequences end-to-end. It appears in everyday language, formal language theory, programming and database systems; it is associative with an empty identity element.

Concatenation is the simple but widely used operation of forming a new sequence by placing one sequence immediately after another. In everyday words, joining "snow" and "ball" yields "snowball." In computing and mathematics the same idea applies to strings of characters, lists, and other finite sequences: the result contains the elements of the first sequence followed by those of the second.

Characteristics and basic properties

The operation has a small set of standard properties that make it easy to reason about. Most importantly, concatenation is associative: (a+b)+c = a+(b+c), so grouping does not affect the result. It is generally not commutative: a+b usually differs from b+a. The empty sequence (often written as "" for strings) acts as an identity element: ""+s = s+"" = s. For finite sequences the length of the result equals the sum of the lengths of the operands.

Notation and common examples

Different contexts use different notations. Juxtaposition (ab) or a dot are common in theoretical work; many programming languages use + for string concatenation (for example Python, Java, JavaScript). SQL uses the double-pipe operator (||) in standard SQL dialects. Some languages provide a named function such as concat(s1,s2) or library routines (for example C's strcat). In functional languages list concatenation often uses symbols like ++. For more overview and references see concatenation.

Concatenation in formal languages and algebra

In formal language theory the operation extends to languages (sets of strings): the concatenation L1L2 is the set of all strings formed by taking one string from L1 followed by one from L2. Repeated concatenation gives rise to the Kleene star, which denotes any finite number (including zero) of repetitions of a language. Algebraically, the set of all strings over an alphabet together with concatenation forms a free monoid: an associative binary operation with an identity element.

Uses, examples and distinctions

Concatenation is ubiquitous in text processing, programming, data formatting, and pattern matching. It underlies operations like building file paths, generating messages, joining tokens in compilers, and composing regular expressions. It differs from numerical addition (which combines values) and from function composition (which chains operations rather than joining sequences). Related operations include interleaving or merging sequences, which preserve relative order within operands but mix elements from each—an operation distinct from straightforward concatenation.

Notable practical points

  • Performance: repeated concatenation can be costly in some languages due to copying; many platforms offer builders or buffers to assemble long results efficiently.
  • Type behavior: some languages overload + for different types, which can cause implicit conversions when concatenating non-string values.
  • Edge cases: empty operands and null-like values behave differently across systems and should be handled explicitly to avoid surprises.

Related articles

Author

AlegsaOnline.com Concatenation: joining strings and sequences in language, math, and computing

URL: https://en.alegsaonline.com/art/22365

Share