← Back to Scala Course | Chapter 2: Variables & Types | Lesson 5 of 8

String

In this page:

  1. String

String

A String is an immutable sequence of characters, written with double quotes. Strings support concatenation with +, a rich set of built-in methods, and interpolation with s"..." (covered in its own tutorial). Because strings are immutable, every "modification" actually creates a new string.

Note: Prefer string interpolation (s"Hello $name") over + concatenation for readability.

Example: String

markup
object Main extends App {
  val first = "Ada"
  val last = "Lovelace"
  val full = first + " " + last

  println(full)
  println(full.length)
  println(full.toUpperCase)
}
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.