https://kotlinlang.org logo
Title
s

Simon Lin

09/24/2021, 4:23 AM
How can we remove items from specify position to end? for example:
list: ["a", "b", "c", "d", "e", "f", "g"]
give specify position: 3
result: ["a", "b", "c"]
e

ephemient

09/24/2021, 5:06 AM
what do you want to do?
list.take(3)
,
list.slice(0..2)
return a new list with a subset of elements
list.subList(0, 3)
returns a view of the original list
mutableList.subList(3, mutableList.size).clear()
removes the tail from a mutable list
s

Simon Lin

09/24/2021, 5:09 AM
If the list is
val data: MutableList<String>
How to modify val
data
list?
I will try
subList
. thx