Char

Common
JVM
JS
Native
1.5
fun Char(code: Int): Char
(source)

Creates a Char with the specified code, or throws an exception if the code is out of Char.MIN_VALUE.code..Char.MAX_VALUE.code.

If the program that calls this function is written in a way that only valid code is passed as the argument, using the overload that takes a UShort argument is preferable (Char(intValue.toUShort())). That overload doesn't check validity of the argument, and may improve program performance when the function is called routinely inside a loop.

import java.util.*
import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val codes = listOf(48, 65, 122, 946)
println(codes.map { Char(it) }) // [0, A, z, β]
println(codes.map { Char(it.toUShort()) }) // [0, A, z, β]

// Char(-1) //  will fail
println(Char(UShort.MIN_VALUE)) // \u0000
// Char(1_000_000) //  will fail
println(Char(UShort.MAX_VALUE)) // \uFFFF
//sampleEnd
}
Common
JVM
Native
1.5

Creates a Char with the specified code.

import java.util.*
import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val codes = listOf(48, 65, 122, 946)
println(codes.map { Char(it) }) // [0, A, z, β]
println(codes.map { Char(it.toUShort()) }) // [0, A, z, β]

// Char(-1) //  will fail
println(Char(UShort.MIN_VALUE)) // \u0000
// Char(1_000_000) //  will fail
println(Char(UShort.MAX_VALUE)) // \uFFFF
//sampleEnd
}
JS
1.5
fun Char(code: <ERROR CLASS>): Char
(source)

Creates a Char with the specified code.

import java.util.*
import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val codes = listOf(48, 65, 122, 946)
println(codes.map { Char(it) }) // [0, A, z, β]
println(codes.map { Char(it.toUShort()) }) // [0, A, z, β]

// Char(-1) //  will fail
println(Char(UShort.MIN_VALUE)) // \u0000
// Char(1_000_000) //  will fail
println(Char(UShort.MAX_VALUE)) // \uFFFF
//sampleEnd
}