Strings in Kotlin can stand alone or be combined with other Strings in a process known as String concatenation. With a plus operator, +, we are able to concatenate or append one String to another resulting in a new word, phrase, or sentence.

Take a look at the following example:

var firstName = "Mike" var lastName = "Wazowski" println(firstName + " " + lastName) // Prints: Mike Wazowski

In the code above, we’ve combined the variables, firstName and lastName to produce a full name with the + operator. Notice how we’ve added an empty String, " ", between the two variables to create natural whitespace between the two words.

In addition to outputting the result of a concatenated String, we can also store this process in a variable for later use. For example:

val userGreeting = firstName + " " + lastName + ", how are you doing today?" println(userGreeting)

The compiler replaces each variable with its value and outputs the final String:

Mike Wazowski, how are you doing today?



In WizardOfOz.kt, use the given variables, dog, state, and movie to output the following quote using String concatenation:

Toto, I've a feeling we're not in Kansas anymore. - The Wizard of Oz, 1939

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?