@Test
fun test1() {
val list = mutableListOf(1, 2, 3, 4, 5, 6)
list.listIterator().let { listIterator ->
while (listIterator.hasNext()) {
listIterator.next().let { data ->
if (data == 3 || data == 5) {
listIterator.remove()
}
}
}
}
println("test1: $list")
}
方式二:
@Test
fun test2() {
val list = mutableListOf(1, 2, 3, 4, 5, 6)
list.removeIf { data ->
data == 3 || data == 5
}
println("test2: $list")
}
方式三:
@Test
fun test3() {
val list = mutableListOf(1, 2, 3, 4, 5, 6)
list.removeAll(list.filter { data ->
data == 3 || data == 5
})
println("test3: $list")
}