Char Type
Veeg om het menu te tonen
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
123456789101112131415package 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.
Bedankt voor je feedback!
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.