This post will discuss how to convert a list of strings to a string array in Kotlin.

1. Using toTypedArray() function

A simple solution to convert a list to a typed array is using the toTypedArray() function. The following solution demonstrates its usage by invoking the toTypedArray() function on List<String>, that results in an Array<String>.

Download Code

Output:

[Washington, D.C., Los Angeles, Seattle]

2. Naive solution

A naive solution allocates storage for the destination string array, and iterate over the list of strings to copy each element to its correct position in the string array. This can be implemented as follows in Kotlin.

Download Code

Output:

[Washington, D.C., Los Angeles, Seattle]

That’s all about converting a List of String to an array of Kotlin String.