This article explores different ways to convert an array to a list using Kotlin.

1. Using toList() function

The standard way to convert an array to a list is with the extension function toList().

Download Code

 
It returns an immutable list instance. To get a mutable list, you can use the toMutableList() function.

Download Code

2. Using Spread Operator

You can also use the listOf() function using the Spread operator by prefixing the array with *.

Download Code

3. Using asList() function

If you just need a wrapper over the original array, you can use the asList() function. It creates a fixed-size list backed by the specified array.

Download Code

4. Using for loop

Another solution is to create an empty list and push every element of the specified array into the list.

Download Code

5. Using addAll() function

Instead of using the for-loop, you can use the addAll() to add all elements of the specified array to the list.

Download Code

That’s all about converting an array to a list in Kotlin.