Convert Array to List in Kotlin
Convert Array to List in Kotlin
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?
2 Answers
2
Kotlin support in the standard library this conversion.
You can use directly
disableNos.toList()
or if you want to make it mutable:
disableNos.toMutableList()
Just because you used Arrays.asList(disabledNos).toList()
– crgarridos
Oct 10 '17 at 9:15
Oops that was very simple:
var integers = disabledNos.toList()
This will give you
List<IntArray>
instead of List<Int>
. @crgarridos's answer is correct.– BakaWaii
Oct 10 '17 at 15:33
List<IntArray>
List<Int>
Oh boy I forgot to remove Arrays.asList() while posting the answer :(
– Audi
Oct 11 '17 at 8:00
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
yep got that...
– Audi
Oct 10 '17 at 9:14