Char

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.3)
class Char : Comparable<Char>
For Common, JVM, JS

Represents a 16-bit Unicode character.

On the JVM, non-nullable values of this type are represented as values of the primitive type char.

For Native

Represents a 16-bit Unicode character.

Functions

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

compareTo

Compares this value with the specified value for order.

fun compareTo(other: Char): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

dec

Decrements this value.

operator fun dec(): Char
Platform and version requirements: Native (1.3)

equals

fun equals(other: Char): Boolean

Indicates whether some other object is "equal to" this one. Implementations must fulfil the following requirements:

fun equals(other: Any?): Boolean
Platform and version requirements: Native (1.3)

hashCode

Returns a hash code value for the object. The general contract of hashCode is:

fun hashCode(): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

inc

Increments this value.

operator fun inc(): Char
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

minus

Subtracts the other Char value from this value resulting an Int.

operator fun minus(other: Char): Int

Subtracts the other Int value from this value resulting a Char.

operator fun minus(other: Int): Char
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

plus

Adds the other Int value to this value resulting a Char.

operator fun plus(other: Int): Char
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

rangeTo

Creates a range from this value to the specified other value.

operator fun rangeTo(other: Char): CharRange
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toByte

Returns the value of this character as a Byte.

fun toByte(): Byte
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toChar

Returns the value of this character as a Char.

fun toChar(): Char
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toDouble

Returns the value of this character as a Double.

fun toDouble(): Double
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toFloat

Returns the value of this character as a Float.

fun toFloat(): Float
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toInt

Returns the value of this character as a Int.

fun toInt(): Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toLong

Returns the value of this character as a Long.

fun toLong(): Long
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toShort

Returns the value of this character as a Short.

fun toShort(): Short
Platform and version requirements: Native (1.3)

toString

Returns a string representation of the object.

fun toString(): String

Companion Object Properties

Platform and version requirements: Native (1.3)

MAX_CODE_POINT

The maximum value of a Unicode code point. Kotlin/Native specific.

const val MAX_CODE_POINT: Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

MAX_HIGH_SURROGATE

The maximum value of a Unicode high-surrogate code unit.

const val MAX_HIGH_SURROGATE: Char
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

MAX_LOW_SURROGATE

The maximum value of a Unicode low-surrogate code unit.

const val MAX_LOW_SURROGATE: Char
Platform and version requirements: Native (1.3)

MAX_RADIX

The maximum radix available for conversion to and from strings.

const val MAX_RADIX: Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

MAX_SURROGATE

The maximum value of a Unicode surrogate code unit.

const val MAX_SURROGATE: Char
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

MAX_VALUE

The maximum value of a character code unit.

const val MAX_VALUE: Char
Platform and version requirements: Native (1.3)

MIN_CODE_POINT

The minimum value of a Unicode code point. Kotlin/Native specific.

const val MIN_CODE_POINT: Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

MIN_HIGH_SURROGATE

The minimum value of a Unicode high-surrogate code unit.

const val MIN_HIGH_SURROGATE: Char
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

MIN_LOW_SURROGATE

The minimum value of a Unicode low-surrogate code unit.

const val MIN_LOW_SURROGATE: Char
Platform and version requirements: Native (1.3)

MIN_RADIX

The minimum radix available for conversion to and from strings.

const val MIN_RADIX: Int
Platform and version requirements: Native (1.3)

MIN_SUPPLEMENTARY_CODE_POINT

The minimum value of a supplementary code point, \u0x10000. Kotlin/Native specific.

const val MIN_SUPPLEMENTARY_CODE_POINT: Int
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

MIN_SURROGATE

The minimum value of a Unicode surrogate code unit.

const val MIN_SURROGATE: Char
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

MIN_VALUE

The minimum value of a character code unit.

const val MIN_VALUE: Char
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

SIZE_BITS

The number of bits used to represent a Char in a binary form.

const val SIZE_BITS: Int
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)

SIZE_BYTES

The number of bytes used to represent a Char in a binary form.

const val SIZE_BYTES: Int

Extension Properties

Platform and version requirements: JVM (1.0)

directionality

Returns the Unicode directionality property for the given character.

val Char.directionality: CharDirectionality

Extension Functions

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

coerceAtLeast

Ensures that this value is not less than the specified minimumValue.

fun <T : Comparable<T>> T.coerceAtLeast(minimumValue: T): T
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

coerceAtMost

Ensures that this value is not greater than the specified maximumValue.

fun <T : Comparable<T>> T.coerceAtMost(maximumValue: T): T
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

coerceIn

Ensures that this value lies in the specified range minimumValue..maximumValue.

fun <T : Comparable<T>> T.coerceIn(
    minimumValue: T?, 
    maximumValue: T?
): T

Ensures that this value lies in the specified range.

fun <T : Comparable<T>> T.coerceIn(
    range: ClosedFloatingPointRange<T>
): T
fun <T : Comparable<T>> T.coerceIn(range: ClosedRange<T>): T
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

downTo

Returns a progression from this value down to the specified to value with the step -1.

infix fun Char.downTo(to: Char): CharProgression
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

equals

Returns true if this character is equal to the other character, optionally ignoring character case.

fun Char.equals(
    other: Char, 
    ignoreCase: Boolean = false
): Boolean
Platform and version requirements: JVM (1.0)

isJavaIdentifierPart

Returns true if this character (Unicode code point) may be part of a Java identifier as other than the first character.

fun Char.isJavaIdentifierPart(): Boolean
Platform and version requirements: JVM (1.0)

isJavaIdentifierStart

Returns true if this character is permissible as the first character in a Java identifier.

fun Char.isJavaIdentifierStart(): Boolean
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

isSurrogate

Returns true if this character is a Unicode surrogate code unit.

fun Char.isSurrogate(): Boolean
Platform and version requirements: JVM (1.0)

isTitleCase

Returns true if this character is a titlecase character.

fun Char.isTitleCase(): Boolean
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

plus

Concatenates this Char and a String.

operator fun Char.plus(other: String): String
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

rangeTo

Creates a range from this Comparable value to the specified that value.

operator fun <T : Comparable<T>> T.rangeTo(
    that: T
): ClosedRange<T>
Platform and version requirements: JVM (1.0)

toTitleCase

Converts this character to titlecase.

fun Char.toTitleCase(): Char
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

until

Returns a range from this value up to but excluding the specified to value.

infix fun Char.until(to: Char): CharRange

Companion Object Extension Functions

Platform and version requirements: Native (1.3)

isSupplementaryCodePoint

Checks if the codepoint specified is a supplementary codepoint or not.

fun Char.Companion.isSupplementaryCodePoint(
    codepoint: Int
): Boolean
Platform and version requirements: Native (1.3)

isSurrogatePair

fun Char.Companion.isSurrogatePair(
    high: Char, 
    low: Char
): Boolean
Platform and version requirements: Native (1.3)

toChars

Converts the codepoint specified to a char array. If the codepoint is not supplementary, the method will return an array with one element otherwise it will return an array A with a high surrogate in A0 and a low surrogate in A1.

fun Char.Companion.toChars(codePoint: Int): CharArray
Platform and version requirements: Native (1.3)

toCodePoint

Converts a surrogate pair to a unicode code point. Doesn't validate that the characters are a valid surrogate pair.

fun Char.Companion.toCodePoint(high: Char, low: Char): Int

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-char/index.html