How to convert intArray to ArrayList<Int> in Kotlin?

UmAnusorn :

From

val array = intArrayOf(5, 3, 0, 2, 4, 1, 0, 5, 2, 3, 1, 4)

I need to convert to ArrayList<Int>

I have tried array.toTypedArray()

But it converted to Array<Int> instead

Ilya :

You can use toCollection function and specify ArrayList as a mutable collection to fill:

val arrayList = intArrayOf(1, 2, 5).toCollection(ArrayList())

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=422418&siteId=1