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

Char

In this page:

  1. Char

Char

A Char represents a single UTF-16 character, written with single quotes, like A. Characters can be compared and cast to their underlying numeric code point with .toInt. Double quotes are reserved for String, not Char, and mixing them up is a common beginner mistake.

Note: Casting a Char to Int with .toInt gives you its Unicode code point.

Example: Char

markup
object Main extends App {
  val letter: Char = 'A'
  val digit: Char = '7'

  println(letter)
  println(letter.toInt)
  println(digit.isDigit)
}
🔒

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.