All lessons

Working with Text

7 min · Kotlin

Join strings, measure them, and use Kotlin string templates.

Kotlin · Working with Text0/5 cleared

Enemy 1 of 5

This code joins two strings with + to make one greeting and prints it. Press Run to see the joined text.

Why this works

Text in Kotlin is stored as a String value, written between double quotes. You can join two strings together with the + operator, the same way you'd combine numbers with addition. Kotlin overloads + so it means concatenation (joining) when both sides are strings.

This works even when mixing a String with other types in some cases (like a String plus a number), because Kotlin will convert the other value to text automatically. Still, using + repeatedly to build up a sentence from many pieces gets clunky fast, which is exactly the problem the next section's string templates solve.

You
Packet Wolf
Loading editor…
Sign up to fightThis one runs on our servers, so it needs a free account.