Working with Text
7 min · Java
Join strings, measure them, and format text with String tools.
Enemy 1 of 5
This code joins two pieces of text with + and prints the result. Press Run to see the greeting and name glued together.
Why this works
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.
Rena
Your AI tutor. She walks you through each step.
Asking for help is part of coding. Rena reads your code and gives you a hint. She is free with an account: 20 hints a day.