In Java or Kotlin, how can I create as much of a sublist as possible? If the range is greater than the size of the list, it should just ignore parts of the range that are out of bounds.
I currently have (Kotlin):
val list: List = arrayListOf(1, 2, 3, 4)
list.subList(0, 3) // -> [1, 2, 3]
list.subList(0, 5) // -> IndexOutOfBoundsException
list.subList(0, 200) // -> IndexOutOfBoundsException
list.clear()
list.subList(0, 3) // -> IndexOutOfBoundsException
I would like (Kotlin):
val list: List = arrayListOf(1, 2, 3, 4)
list.subList(0, 3) // -> [1, 2, 3]
list.subList(0, 5) // -> [1, 2, 3, 4]
list.subList(0, 200) // -> [1, 2, 3, 4]
list.clear()
list.subList(0, 3) // -> []