How can I create a sublist in Java or Kotlin that will return as many items as possible, without throwing an IndexOutOfBoundsException, regardless of the size of the list?
val list: List = arrayListOf(1, 2, 3, 4)
I want to create a sublist from list that will return as many items as possible without throwing an IndexOutOfBoundsException, regardless of the size of the list. For example: