> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kotlin Char

A `Char` in Kotlin represents a single 16-bit Unicode character. On the JVM, it is backed by the primitive `char` type and represents a UTF-16 code unit. Unlike Java, Kotlin enforces strict type safety and does not treat characters as numeric types; implicit widening conversions from `Char` to `Int` or other numeric types are strictly prohibited.

## Instantiation and Syntax

Character literals are defined by enclosing the character in single quotes. They can be instantiated using standard characters, Unicode escape sequences, or explicit conversion from integer code points.

```kotlin theme={"dark"}
val letter: Char = 'A'
val unicodeChar: Char = '\u0041' // Represents 'A'
val fromCode: Char = Char(65)    // Represents 'A'
```

## Escape Sequences

Kotlin supports standard escape sequences for special characters, prefixed with a backslash (`\`):

* `\t` – Tab
* `\b` – Backspace
* `\n` – Newline (LF)
* `\r` – Carriage return (CR)
* `\'` – Single quote
* `\"` – Double quote
* `\\` – Backslash
* `\$` – Dollar sign (required to escape string interpolation syntax)

## Operations

`Char` supports specific arithmetic and relational operations evaluated against their underlying Unicode code points.

**Arithmetic Operations**
Adding or subtracting an `Int` to or from a `Char` yields a new `Char` offset by that integer value. Subtracting one `Char` from another yields an `Int` representing the mathematical distance between their code points.

```kotlin theme={"dark"}
val nextChar: Char = 'A' + 1  // 'B'
val prevChar: Char = 'C' - 1  // 'B'
val distance: Int = 'Z' - 'A' // 25
```

**Comparison and Ranges**
`Char` implements the `Comparable<Char>` interface, enabling the use of standard relational operators (`<`, `<=`, `>`, `>=`). It also supports range operators (`..`, `..<`) to generate a `CharRange` progression.

```kotlin theme={"dark"}
val isGreater: Boolean = 'b' > 'a' // true
val charRange: CharRange = 'a'..'z'
val halfOpenRange: CharRange = 'A'..<'Z'
```

## Type Conversion

Because `Char` is not implicitly treated as a number, explicit property access is required to retrieve its underlying integer value. As of Kotlin 1.5, the `.code` property is the standard mechanism for this extraction, replacing the deprecated `.toInt()` function.

```kotlin theme={"dark"}
val char: Char = 'X'
val codePoint: Int = char.code // 88

// Converting an Int back to a Char
val restoredChar: Char = Char(codePoint) // 'X'
```

## Nullability and Boxing

When a `Char` is declared as nullable (`Char?`), used as a generic type argument (e.g., `List<Char>`), or instantiated as a generic array (`Array<Char>`), the Kotlin compiler automatically boxes the primitive into a `java.lang.Character` object on the JVM. This boxing incurs memory overhead and requires unboxing during arithmetic or relational operations.

To avoid boxing overhead when working with arrays of characters, Kotlin provides the specialized `CharArray` type, which compiles directly to a primitive `char[]` on the JVM. Non-nullable `Char` declarations are compiled to unboxed primitives whenever possible.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Kotlin Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
