Kotlin 可变集合与不可变集合的创建与转换

fun main() {
    val list = listOf("Jason", "Jack", "Jacky")
    val mutableListOf = mutableListOf("Jason", "Jack", "Jacky")
    mutableListOf.add("狗蛋")
    mutableListOf.remove("Jack")
    println(mutableListOf)

    //集合转换为可变集合
   val res= list.toMutableList()
    //可变集合转换为集合
    mutableListOf.toList()
    res.add("狗蛋")
    println(res)


}

猜你喜欢

转载自blog.csdn.net/mp624183768/article/details/123798797
今日推荐