Complete the code to create a Kotlin sequence from a list.
val numbers = listOf(1, 2, 3, 4, 5) val seq = numbers.[1]()
Use asSequence() to convert a list to a Kotlin sequence.
Complete the code to filter even numbers using a Kotlin sequence.
val numbers = listOf(1, 2, 3, 4, 5) val evens = numbers.asSequence().[1] { it % 2 == 0 }.toList()
The filter function selects elements matching the condition.
Fix the error in the code to convert a Kotlin sequence back to a list.
val seq = listOf(1, 2, 3).asSequence() val list = seq.[1]()
Use toList() to convert a sequence back to a list.
Fill both blanks to create a Java stream from a list and collect it back to a list.
val list = listOf(1, 2, 3, 4) val stream = list.[1]() val result = stream.collect(Collectors.[2]())
Use stream() to get a Java stream and Collectors.toList() to collect it back to a list.
Fill all three blanks to create a Kotlin sequence, filter odd numbers, and convert to a list.
val numbers = listOf(1, 2, 3, 4, 5) val result = numbers.[1]().[2] { it % 2 != 0 }.[3]()
First convert to a sequence with asSequence(), then filter odd numbers with filter, and finally convert back to a list with toList().