I want to make sublist that contains last element ...
# announcements
i
I want to make sublist that contains last element of my original list, however
list.subList()
2nd param
toIndex
is not end inclusive đŸ¤”
Copy code
//have
val list = listOf(1,2,3,4)

//want sublist
listOf(3,4)
g
What about listOf(1,2,3,4).takeLast(2)?
a
listOf(1,2,3,4).subList(2,4)
?
i
@arekolek It’s what I need however its a bit wired that I am passing non existing index as a param. ANyway thanks for help
a
I think that’s a pretty common way of indexing, nothing to be worried about đŸ˜„
p
d
@igor.wojda that way you can see at a glance how many items will be in the sub list :) end of ranges is usually exclusive in kotlin (with the exception of .. operator, unfortunately)