Strings and Other Literals

In the following lesson, you will be introduced to literals.

By now, you must have noticed that we haven’t discussed strings. Strings do not fall under anyVal in the data type hierarchy. This raises the question: what are strings?

The single word answer is ‘literals’.


A literal is defined as taking anything in its most usual and basic sense. Mapping this onto computer programming, literals are fixed values appearing directly as is in the source code. For example, “Hello World”, 55, and ‘A’ are all literals.

String Literals

Strings literals are a combination of characters surrounded by double quotation marks. The syntax for declaring a variable of type String is the same as declaring a variable of any basic value type.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy