You are not limited to retrieving single elements from a collection. You can also retrieve parts of a collection, or slices.
These are some of the functions available in the Kotlin SDK:
slice - returns a list of elements at the specified indices.
take - returns a list of the first n elements.
takeLast - returns a list of the last n elements.
takeWhile - returns a list of elements that match the predicate.
drop - returns a list of elements after the first n elements.
dropLast - returns a list of elements before the last n elements.
dropWhile - returns a list of elements after the first element that does not match the predicate.
Examples of using these functions:
val numbers = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val slice = numbers.slice(2..5) // [3, 4, 5, 6]
val firstThree = numbers.take(3) // [1, 2, 3]
val lastThree = numbers.takeLast(3) // [8, 9, 10]
val takeWhileSmall = numbers.takeWhile { it < 5 } // [1, 2, 3, 4]
val dropFirst = numbers.drop(3) // [4, 5, 6, 7, 8, 9, 10]
val dropLast = numbers.dropLast(3) // [1, 2, 3, 4, 5, 6, 7]