Char
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.
Since Kotlin
1.5
Samples
import samples.*
import java.util.*
import kotlin.test.*
fun main() {
//sampleStart
val codes = listOf(48, 65, 122, 946)
assertPrints(codes.map { Char(it) }, "[0, A, z, β]")
assertPrints(codes.map { Char(it.toUShort()) }, "[0, A, z, β]")
assertFails { Char(-1) }
assertPrints(Char(UShort.MIN_VALUE), "\u0000")
assertFails { Char(1_000_000) }
assertPrints(Char(UShort.MAX_VALUE), "\uFFFF")
//sampleEnd
}
Creates a Char with the specified code.
Since Kotlin
1.5
Samples
import samples.*
import java.util.*
import kotlin.test.*
fun main() {
//sampleStart
val codes = listOf(48, 65, 122, 946)
assertPrints(codes.map { Char(it) }, "[0, A, z, β]")
assertPrints(codes.map { Char(it.toUShort()) }, "[0, A, z, β]")
assertFails { Char(-1) }
assertPrints(Char(UShort.MIN_VALUE), "\u0000")
assertFails { Char(1_000_000) }
assertPrints(Char(UShort.MAX_VALUE), "\uFFFF")
//sampleEnd
}
Creates a Char with the specified code.
Since Kotlin
1.5
Samples
import samples.*
import java.util.*
import kotlin.test.*
fun main() {
//sampleStart
val codes = listOf(48, 65, 122, 946)
assertPrints(codes.map { Char(it) }, "[0, A, z, β]")
assertPrints(codes.map { Char(it.toUShort()) }, "[0, A, z, β]")
assertFails { Char(-1) }
assertPrints(Char(UShort.MIN_VALUE), "\u0000")
assertFails { Char(1_000_000) }
assertPrints(Char(UShort.MAX_VALUE), "\uFFFF")
//sampleEnd
}
Creates a Char with the specified code.
Since Kotlin
1.5
Samples
import samples.*
import java.util.*
import kotlin.test.*
fun main() {
//sampleStart
val codes = listOf(48, 65, 122, 946)
assertPrints(codes.map { Char(it) }, "[0, A, z, β]")
assertPrints(codes.map { Char(it.toUShort()) }, "[0, A, z, β]")
assertFails { Char(-1) }
assertPrints(Char(UShort.MIN_VALUE), "\u0000")
assertFails { Char(1_000_000) }
assertPrints(Char(UShort.MAX_VALUE), "\uFFFF")
//sampleEnd
}
Creates a Char with the specified code.
Since Kotlin
1.5
Samples
import samples.*
import java.util.*
import kotlin.test.*
fun main() {
//sampleStart
val codes = listOf(48, 65, 122, 946)
assertPrints(codes.map { Char(it) }, "[0, A, z, β]")
assertPrints(codes.map { Char(it.toUShort()) }, "[0, A, z, β]")
assertFails { Char(-1) }
assertPrints(Char(UShort.MIN_VALUE), "\u0000")
assertFails { Char(1_000_000) }
assertPrints(Char(UShort.MAX_VALUE), "\uFFFF")
//sampleEnd
}