Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Char Type | Core Data Types
Kotlin Data Types

bookChar Type

Swipe to show menu

The Char type in Kotlin is used to represent a single character. You declare a Char variable using single quotes around the character, such as 'A' or '1'. Unlike String, which can hold multiple characters, a Char always holds exactly one character. Valid Char values include letters, digits, symbols, or special escape characters.

Main.kt

Main.kt

copy
123456789101112131415
package com.example; fun main() { val letterA: Char = 'A' val digitOne: Char = '1' val dollarSign: Char = '$' val newLine: Char = '\n' val tabChar: Char = '\t' println("Letter A: $letterA") println("Digit One: $digitOne") println("Dollar Sign: $dollarSign") println("New Line (shows as line break): [$newLine]") println("Tab Character (shows as tab space): [${tabChar}Tab]") }

Escape characters allow you to represent special characters in a Char value using a backslash (\). For instance, \n represents a newline character, and \t represents a tab. In the code above, val newLine: Char = '\n' assigns the newline character to a variable, and val tabChar: Char = '\t' assigns the tab character. When you print these characters, they control formatting in the console output rather than displaying as visible symbols.

question mark

Which of the following is a valid Char declaration in Kotlin?

Select all correct answers

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 3

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

SectionΒ 1. ChapterΒ 3
some-alt