学无先后,达者为师

网站首页 编程语言 正文

Kotlin 集合也可以进行+= -= 还可以根据条件进行删除(removeIf)

作者:安果移不动 更新时间: 2022-05-12 编程语言
fun main() {
    val list = listOf("Jason", "Jack", "Jacky")
    val mutableListOf = mutableListOf("Jason", "Jack", "Jacky")
    mutableListOf.add("狗蛋")
    println(mutableListOf)
    //相当于add
    mutableListOf += "张三"
    println(mutableListOf)
    // 相当于remove
    mutableListOf -= "狗蛋"
    println(mutableListOf)
    //根据条件一出
    mutableListOf.removeIf{ it.contains("J")}
    println(mutableListOf)
}

非常的时尚

原文链接:https://blog.csdn.net/mp624183768/article/details/123829162

栏目分类
最近更新