0Pricing
Kotlin Academy · Lesson

Char and Custom Ranges

Beyond integers.

Beyond Integers

Ranges are not just for Int. Kotlin supports ranges of characters and other comparable types.

This lesson explores char ranges and how custom types can join in with rangeTo.

Char Ranges Recap

Characters have a defined order, so 'a'..'z' is a valid range.

You can iterate, check membership, and more.

fun main() {
    for (c in 'a'..'f') print(c)
    println()
    println('q' in 'a'..'z')
}

All lessons in this course

  1. Range Operators
  2. Step and downTo
  3. Ranges in Loops
  4. Char and Custom Ranges
← Back to Kotlin Academy