0
0
Kotlinprogramming~5 mins

Char type and Unicode behavior in Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the Kotlin Char type used for?
The Char type in Kotlin represents a single character, such as a letter, digit, or symbol. It holds a 16-bit Unicode character.
Click to reveal answer
intermediate
How does Kotlin store characters internally in the Char type?
Kotlin stores Char as a 16-bit value representing a UTF-16 code unit, which can represent most common Unicode characters directly.
Click to reveal answer
intermediate
What happens when a Unicode character requires more than 16 bits in Kotlin's Char type?
Characters outside the Basic Multilingual Plane (BMP) need two Char values called a surrogate pair to represent one Unicode character in Kotlin.
Click to reveal answer
beginner
How can you represent a Unicode character in Kotlin using escape sequences?
You can use the syntax \uXXXX where XXXX is the 4-digit hexadecimal Unicode code unit for the character, e.g., '\u0041' for 'A'.
Click to reveal answer
intermediate
Why might a Kotlin String have a different length than the number of Unicode characters it displays?
Because Kotlin String length counts Char units (UTF-16 code units), some characters (like emojis) use two Char units, so length can be greater than visible characters.
Click to reveal answer
What Kotlin type is used to store a single Unicode character?
AChar
BString
CInt
DByte
How many bits does a Kotlin Char use internally?
A32 bits
B8 bits
C16 bits
D64 bits
What is a surrogate pair in Kotlin's Unicode handling?
AA pair of integers
BTwo <code>Char</code> values representing one Unicode character outside BMP
CA pair of strings
DA Kotlin keyword
How do you write the Unicode character 'A' using an escape sequence in Kotlin?
A'\u0041'
B'\x41'
C'\u41'
D'\U0041'
Why might string.length be larger than the number of visible characters?
ABecause of string encoding errors
BBecause Kotlin counts words, not characters
CBecause of trailing spaces
DBecause some characters use two <code>Char</code> units (surrogate pairs)
Explain how Kotlin's Char type represents Unicode characters and what happens with characters outside the Basic Multilingual Plane.
Think about how UTF-16 encoding works with Kotlin's Char.
You got /4 concepts.
    Describe how to use Unicode escape sequences in Kotlin to represent characters and why string length might not match visible characters.
    Consider how Kotlin counts characters internally versus what you see.
    You got /4 concepts.