All lessons

Working with Text

7 min · Java

Join strings, measure them, and format text with String tools.

Java · Working with Text0/5 cleared

Enemy 1 of 5

Text is stored in String objects — the word "objects" matters here: unlike int or double, String is a full-fledged class in Java, which is why it comes with built-in methods (shown below) rather than just being a raw value.

Join two strings with + (concatenation) — the same operator used for addition, but Java uses it for gluing text together whenever at least one side is a String. This double duty is convenient, and it also means you can mix a String and a number with + (like "Score: " + 10) and Java will automatically convert the number to text for you — a small but handy difference from stricter languages.

You
Packet Wolf

Loading editor...

Ln 1, Col 1Spaces: 4
Sign up to fightTarget output: Hello, Ada