Convert Array to List in Kotlin

2019-04-19 08:36发布

问题:

I try to do this with (same as java)

val disabledNos = intArrayOf(1, 2, 3, 4)
var integers = Arrays.asList(disabledNos)

but this doesn't give me a list. Any ideas?

回答1:

Kotlin support in the standard library this conversion.

You can use directly

disableNos.toList()

or if you want to make it mutable:

disableNos.toMutableList()


回答2:

Oops that was very simple:

var integers = disabledNos.toList()


标签: kotlin