This article explores different ways to convert a string to a character array in Kotlin.

1. Using toCharArray() function

The standard solution to convert a string to a character array is with the toCharArray() function.

Download Code

 
The toCharArray() function returns a CharArray containing characters in the string. If you need a typed array, make an extra call to the toTypedArray() function.

Download Code

2. Using for loop

You can also use a for-loop to read the characters in the string and assign them to a Char Array.

Download Code

That’s all about converting a string to the Character array in Kotlin.