Thanks for your feedback!
Was this page helpful?
Returns a sequence containing first n elements.
The operation is intermediate and stateless.
if n is negative.
import kotlin.math.* import kotlin.test.* fun main() { //sampleStart val chars = ('a'..'z').toList() println(chars.take(3)) // [a, b, c] println(chars.takeWhile { it < 'f' }) // [a, b, c, d, e] println(chars.takeLast(2)) // [y, z] println(chars.takeLastWhile { it > 'w' }) // [x, y, z] //sampleEnd }
xxxxxxxxxx
val chars = ('a'..'z').toList()
println(chars.take(3)) // [a, b, c]
println(chars.takeWhile { it < 'f' }) // [a, b, c, d, e]
println(chars.takeLast(2)) // [y, z]
println(chars.takeLastWhile { it > 'w' }) // [x, y, z]
Thanks for your feedback!