Char

Common
JVM
JS
Native
1.0
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

Common
JVM
JS
Native
1.0

compareTo

Compares this value with the specified value for order.

fun compareTo(other: Char): Int
Common
JVM
JS
Native
1.0

dec

Decrements this value.

operator fun dec(): Char
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
Native
1.3

hashCode

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

fun hashCode(): Int
Common
JVM
JS
Native
1.0

inc

Increments this value.

operator fun inc(): Char
Common
JVM
JS
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
Common
JVM
JS
Native
1.0

plus

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

operator fun plus(other: Int): Char
Common
JVM
JS
Native
1.0

rangeTo

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

operator fun rangeTo(other: Char): CharRange
Common
JVM
JS
Native
1.0

toByte

Returns the value of this character as a Byte.

fun toByte(): Byte
Common
JVM
JS
Native
1.0

toChar

Returns the value of this character as a Char.

fun toChar(): Char
Common
JVM
JS
Native
1.0

toDouble

Returns the value of this character as a Double.

fun toDouble(): Double
Common
JVM
JS
Native
1.0

toFloat

Returns the value of this character as a Float.

fun toFloat(): Float
Common
JVM
JS
Native
1.0

toInt

Returns the value of this character as a Int.

fun toInt(): Int
Common
JVM
JS
Native
1.0

toLong

Returns the value of this character as a Long.

fun toLong(): Long
Common
JVM
JS
Native
1.0

toShort

Returns the value of this character as a Short.

fun toShort(): Short
Native
1.3

toString

Returns a string representation of the object.

fun toString(): String

Companion Object Properties

Native
1.3

MAX_CODE_POINT

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

const val MAX_CODE_POINT: Int
Common
JVM
JS
Native
1.0

MAX_HIGH_SURROGATE

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

const val MAX_HIGH_SURROGATE: Char
Common
JVM
JS
Native
1.0

MAX_LOW_SURROGATE

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

const val MAX_LOW_SURROGATE: Char
Native
1.3

MAX_RADIX

The maximum radix available for conversion to and from strings.

const val MAX_RADIX: Int
Common
JVM
JS
Native
1.0

MAX_SURROGATE

The maximum value of a Unicode surrogate code unit.

const val MAX_SURROGATE: Char
Common
JVM
JS
Native
1.3

MAX_VALUE

The maximum value of a character code unit.

const val MAX_VALUE: Char
Native
1.3

MIN_CODE_POINT

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

const val MIN_CODE_POINT: Int
Common
JVM
JS
Native
1.0

MIN_HIGH_SURROGATE

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

const val MIN_HIGH_SURROGATE: Char
Common
JVM
JS
Native
1.0

MIN_LOW_SURROGATE

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

const val MIN_LOW_SURROGATE: Char
Native
1.3

MIN_RADIX

The minimum radix available for conversion to and from strings.

const val MIN_RADIX: Int
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
Common
JVM
JS
Native
1.0

MIN_SURROGATE

The minimum value of a Unicode surrogate code unit.

const val MIN_SURROGATE: Char
Common
JVM
JS
Native
1.3

MIN_VALUE

The minimum value of a character code unit.

const val MIN_VALUE: Char
Common
JVM
JS
Native
1.3

SIZE_BITS

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

const val SIZE_BITS: Int
Common
JVM
JS
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

JVM
1.0

directionality

Returns the Unicode directionality property for the given character.

val Char.directionality: CharDirectionality

Extension Functions

Common
JVM
JS
Native
1.0

coerceAtLeast

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

fun <T : Comparable<T>> T.coerceAtLeast(minimumValue: T): T
Common
JVM
JS
Native
1.0

coerceAtMost

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

fun <T : Comparable<T>> T.coerceAtMost(maximumValue: T): T
Common
JVM
JS
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
Common
JVM
JS
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
Common
JVM
JS
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
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
JVM
1.0

isJavaIdentifierStart

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

fun Char.isJavaIdentifierStart(): Boolean
Common
JVM
JS
Native
1.0

isSurrogate

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

fun Char.isSurrogate(): Boolean
JVM
1.0

isTitleCase

Returns true if this character is a titlecase character.

fun Char.isTitleCase(): Boolean
Common
JVM
JS
Native
1.0

plus

Concatenates this Char and a String.

operator fun Char.plus(other: String): String
Common
JVM
JS
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>
JVM
1.0

toTitleCase

Converts this character to titlecase.

fun Char.toTitleCase(): Char
Common
JVM
JS
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

Native
1.3

isSupplementaryCodePoint

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

fun Char.Companion.isSupplementaryCodePoint(
    codepoint: Int
): Boolean
Native
1.3

isSurrogatePair

fun Char.Companion.isSurrogatePair(
    high: Char,
    low: Char
): Boolean
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
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