Home

Concatenation

Concatenation is the operation of joining two or more sequences end-to-end to form a new sequence. In computing, strings are the most common sequences concatenated, but concatenation also applies to lists, arrays, and other sequence types. In many programming languages, concatenation is exposed through operators (such as +) or through dedicated functions (such as concat or join). The result preserves the order of the operands, and the length of the result is the sum of the lengths of the operands.

Mathematically, concatenation is a binary operation on sequences. For strings over an alphabet, it is associative:

In practical computing, the way concatenation is implemented affects performance. When strings are immutable, naive repeated

Applications include constructing text from tokens, assembling data records, or combining identifiers. In databases, concatenation is

(xy)z
=
x(yz).
The
empty
string
ε
acts
as
the
identity
element,
since
xε
=
εx
=
x.
The
concept
extends
to
other
sequence-like
structures,
including
lists,
arrays,
and
languages,
forming
a
monoid
under
concatenation
with
the
appropriate
identity
element.
concatenation
can
create
many
intermediate
copies,
leading
to
inefficient,
quadratic-time
behavior
in
the
total
length.
Many
languages
provide
optimized
approaches:
mutable
buffers
or
string
builders
that
accumulate
content
before
producing
a
final
string,
or
join
operations
that
allocate
the
final
size
once.
Functional
styles
may
reduce
the
number
of
allocations
by
folding
a
collection
with
a
dedicated
strategy.
used
to
merge
string
fields
(for
example,
to
form
full
names).
In
formal
language
theory,
concatenation
of
languages
L
and
M
is
defined
as
{xy
|
x
in
L,
y
in
M}.
Overall,
concatenation
is
a
fundamental
and
widely
used
operation
in
programming,
data
processing,
and
theory.