kotlin list remove
val nums = mutableListOf(-3, -2, 4, -1, 0, 1, 2, 3, 4, 2, 5, 6, 5, 8)
nums.removeAt(4)
// [-3, -2, 4, -1, 1, 2, 3, 4, 2, 5, 6, 5, 8]
nums.remove(4)
// [-3, -2, -1, 1, 2, 3, 4, 2, 5, 6, 5, 8]
nums.removeAll(listOf(1, 2, 3))
// [-3, -2, -1, 4, 5, 6, 5, 8]
nums.removeAll({ it < -1 })
// [-1, 4, 5, 6, 5, 8]
nums -= listOf(4, 5)
// [-1, 6, 8]
nums.removeAt(0) // remove first element
// [6, 8]
nums.removeAt(nums.size - 1) // remove last element
// [6]
nums.clear()
// []
Are there any code examples left?
New code examples in category Java