This article explores different ways to convert Array<Any> to Array<Int> in Kotlin.

1. Using map() function

Here, the idea is to convert the array into a list and transform each element into a corresponding int value using the map() function. Finally, return the list as an array using toTypedArray() function.

Download Code

2. Using System.arraycopy() function

Another solution is to use the System.arraycopy() to copy an array to another array. This will work fine for arrays of different types when an element in the source array can be stored in the destination array.

Download Code

3. Custom Routine

The idea is to iterate over the array using a for-loop and copy every element to an integer array after converting it into its corresponding integer value.

Download Code

That’s all about converting an Object array to an Integer array in Kotlin.