Learn
Using Text Variables
Strings & Characters

In this lesson, we’ll continue working with variables and take a deeper dive into the data types Strings and Characters.

illustration of a String

Recall that a String in Kotlin is a sequence of characters wrapped in double-quotes. Its characters can include various combinations of digits, letters, symbols, and whitespace.

var variableName: String = "some text"  

Strings are made up of characters and in Kotlin, a character is a data type representing a single letter, digit, or symbol wrapped in single quotes. It is denoted by the Char type.

var variableName: Char = 'A' 

Some things to keep in mind about characters:

  • The character, 'A', is not the same as 'a' as these letters represent different Unicodes and won’t be recognized as equivalent by the compiler.

  • The character, '1', is not the same as the integer, 1, as these values signify two different types of data: Char and Int.

Reference Kotlin’s documentation to learn more about Strings and Characters.

Instructions

Take a look at the code editor on the right and observe some of the shorthand variable declarations for String and Char values.

Click Next when you’re ready to move on.

Folder Icon

Take this course for free

Already have an account?