A CharSequence (e.g. String) can be empty, have a single character, or have more than one character.

If you want a function that "returns the single character, or throws an exception if the char sequence is empty or has more than one character" then you want single:

val string = "A"
val char = string.single()
println(char)

And if you want to call single by a different name you can create your own extension function to do so:

fun CharSequence.toChar() = single()

Usage:

val string = "A"
val char = string.toChar()
println(char)
Answer from mfulton26 on Stack Overflow
🌐
Kotlin
kotlinlang.org › api › core › kotlin-stdlib › kotlin.text › to-char-array.html
toCharArray | Core API – Kotlin Programming Language
@IgnorableReturnValueexpect fun ... 0, endIndex: Int = length): CharArray(source) Copies characters from this string into the destination character array and returns that array....
Discussions

How do I split a string into single characters and put them into a list?
If you want to get a List in the result, calling toList() would be the most straightforward solution: "banana".toList() More on reddit.com
🌐 r/Kotlin
8
1
November 30, 2021
CharArray.concatToString() vs. CharArray.joinToString("") - Support - Kotlin Discussions
Given I have a CharArray. I want to convert to a String. Could someone tell me which of the following methods is better and why · The code above needs 2 steps: “string to array” then “array to string”. Is there any way to make it perform better · Remember strings in Java/Kotlin are ... More on discuss.kotlinlang.org
🌐 discuss.kotlinlang.org
0
September 26, 2022
How can I convert CharArray / Array<Char> to a String? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
String to Array - Kotlin Discussions
Is there a way to separate a string into an array of characters? Or does Kotlin have an equivalent to .charAt()? More on discuss.kotlinlang.org
🌐 discuss.kotlinlang.org
0
July 17, 2018
🌐
Baeldung
baeldung.com › home › kotlin › kotlin strings › convert string to char in kotlin
Convert String to Char in Kotlin | Baeldung on Kotlin
April 7, 2025 - We should use this method on a string when we are certain we are only interested in the first character of that string. Lastly, we can leverage the toCharArray() method. This method returns an Array of characters representing the same sequence ...
🌐
TutorialsPoint
tutorialspoint.com › kotlin › kotlin_string_tochararray_function.htm
Kotlin String - toCharArray() Function
Following is the basic example of converting a string to a character array using the toCharArray() − · fun main() { val string = "tutorialspoint" val charArray = string.toCharArray() println(charArray.joinToString()) } ... fun main() { val ...
🌐
TutorialKart
tutorialkart.com › kotlin › kotlin-convert-string-to-char-array
Kotlin – Convert string to char array
May 10, 2023 - To convert a string to character array in Kotlin, use String.toCharArray() method.
🌐
Kotlin
kotlinlang.org › api › latest › jvm › stdlib › kotlin.text › to-char-array.html
toCharArray - Kotlin Programming Language
August 10, 2022 - fun String.toCharArray( destination: ... (JVM source) (JS source) (Native source) Copies characters from this string into the destination character array and returns that array....
🌐
Reddit
reddit.com › r/kotlin › how do i split a string into single characters and put them into a list?
r/Kotlin on Reddit: How do I split a string into single characters and put them into a list?
November 30, 2021 -

Hallo fellow Kotliners,

I started learning Kotlin and I wanted to do a littler excersise.

I want to split "banana" into single characters and put them into a list.
Input : "banana"
Output: [ 'b', 'a', 'n', 'a', 'n', 'a' ]

I tried googling around an looking stuff up, but it did not work out.
Can you please help me solving this?

🌐
Programiz
programiz.com › kotlin-programming › examples › char-string
Kotlin Program to Convert Character to String and Vice-Versa
In this program, you'll learn to convert a character (char) to a string and vice-versa in Kotlin.
Find elsewhere
🌐
Kotlin Discussions
discuss.kotlinlang.org › support
CharArray.concatToString() vs. CharArray.joinToString("") - Support - Kotlin Discussions
September 26, 2022 - Given I have a CharArray. I want to convert to a String. Could someone tell me which of the following methods is better and why? CharArray.concatToString() CharArray.joinToString("")
🌐
IncludeHelp
includehelp.com › kotlin › convert-string-to-character-array.aspx
Kotlin program to convert string to character array
package com.includehelp import java.util.* //Main Function, entry Point of Program fun main(args: Array<String>) { // InputStream to get Input val scanner = Scanner(System.`in`) //Input String print("Enter String : ") var str = scanner.nextLine() //convert String to Character Array val charArray = str.toCharArray() //Print Character Array get from String println("Character Array Elements : ${charArray.contentToString()} ") }
🌐
Kotlin
kotlinandroid.org › kotlin android home › kotlin tutorials › kotlin string tutorials › kotlin – convert string into an array of characters
Convert String into an Array of Characters - Kotlin Android
To convert a given string into an array of characters in Kotlin, call toCharArray() function on the given string. The function returns an array of characters.
🌐
W3cubDocs
docs.w3cub.com › kotlin › api › latest › jvm › stdlib › kotlin.text › to-char-array
kotlin.text.toCharArray - Kotlin - W3cubDocs
fun StringBuilder.toCharArray( destination: CharArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = this.length) Copies characters from this string builder into the destination character array.
🌐
Baeldung
baeldung.com › home › kotlin › kotlin strings › convert a character array to a string in kotlin
Convert a Character Array to a String in Kotlin | Baeldung on Kotlin
September 7, 2024 - Here, we create an Array of Char type. Then, we call the joinToString() factory function and turn the Array into a String.
🌐
Kotlin
kotlinlang.org › api › latest › jvm › stdlib › kotlin › -char-array
CharArray - Kotlin Programming Language
Try the revamped Kotlin docs design! ... An array of chars. When targeting the JVM, instances of this class are represented as char[]. An array of chars. ... Creates a new array of the specified size, where each element is calculated by calling the specified init function. ... Creates a new array of the specified size, with all elements initialized to null char (`\u0000').
🌐
Kotlin Discussions
discuss.kotlinlang.org › t › string-to-array › 8592
String to Array - Kotlin Discussions
July 17, 2018 - Is there a way to separate a string into an array of characters? Or does Kotlin have an equivalent to .charAt()?
🌐
Reddit
reddit.com › r/kotlin › unicode string to chararray?
r/Kotlin on Reddit: Unicode string to charArray?
July 27, 2023 -

toCharArray() toByteArray() // using charser = Charsets.UTF-32

These wont work. Char is just 16 bit. Unicode might be more than that.

val str = “இன்று”

It has just three unicode characters…

I tried to separate the characters using

str.codePoints().toArray().size Returns 5

So i think contains surrogate pair. I cant find enough details in the document regarding surrogate pair or codePoints

How do i take each unicode character from that string and store it in an array?

I tried to find the high and low surrogates using isHighSurrogate() ( toCharArray() )

It is not working. Is it a bug?

🌐
Kotlin
kotlinlang.org › api › core › kotlin-stdlib › kotlin › -char-array
CharArray | Core API – Kotlin Programming Language
The array is expected to be sorted, otherwise the result is undefined. ... Returns 1st element from the array. ... Returns 2nd element from the array. ... Returns 3rd element from the array. ... Returns 4th element from the array. ... Returns 5th element from the array. ... Concatenates characters in this CharArray into a String...
🌐
Java Guides
javaguides.net › 2024 › 11 › kotlin-string-tochararray.html
Kotlin String toCharArray
November 12, 2024 - This function belongs to the String ... its individual characters. ... The toCharArray function converts a string into an array of characters, allowing you to work with each character individually....