This article explores different ways to convert between lists of different types in Kotlin.

You can use the map() function to easily convert a list of one type to a list of another type. It returns a list containing the results of applying the specified transform function to each element in the original list.

 
For example, the following code converts a List<Integer> to a List<String>:

Download Code

Output:

[1, 2, 3, 4, 5]

 
To do the opposite, i.e. convert List<String> to List<Integer>, you can do like:

Download Code

Output:

[1, 2, 3, 4, 5]

That’s all about conversion between lists of different types in Kotlin.