← All lessons/Variables & Data Types· Lesson 7 of 32

Strings & text

Hold text in strings and join pieces together with + to build a message.

About 6 min

Text is a string

A string is a piece of text wrapped in quotes, like "hello". Quotes are how the computer knows it's text and not code. You can store a string in a variable just like a number.

Joining strings

The + operator concatenates strings — it sticks them end to end. Notice the space inside the quotes; without it the words would jam together:

Building a greeting from two pieces.

TIP

You can join text and numbers too: "Score: " + 42 becomes the string "Score: 42".

Your turn

Declare a variable name holding any name as a string. Then build a string greeting by concatenating "Hello, ", the name, and "!", and println it. The output must contain the word Hello.

Hints