将数组转换为Kotlin中的列表 [英] Convert Array to List in Kotlin

查看:355
本文介绍了将数组转换为Kotlin中的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用(与java相同)

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?

推荐答案

标准库中的Kotlin支持此转换.

Kotlin support in the standard library this conversion.

您可以直接使用

disableNos.toList()

或者如果您想使其可变:

or if you want to make it mutable:

disableNos.toMutableList()

这篇关于将数组转换为Kotlin中的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆