fun <T> Array<out T>.takeLast(n: Int): List<T>
fun ByteArray.takeLast(n: Int): List<Byte>
fun ShortArray.takeLast(n: Int): List<Short>
fun IntArray.takeLast(n: Int): List<Int>
fun LongArray.takeLast(n: Int): List<Long>
fun FloatArray.takeLast(n: Int): List<Float>
fun DoubleArray.takeLast(n: Int): List<Double>
fun BooleanArray.takeLast(n: Int): List<Boolean>
fun CharArray.takeLast(n: Int): List<Char>
fun <T> List<T>.takeLast(n: Int): List<T>
@ExperimentalUnsignedTypes fun UIntArray.takeLast( n: Int ): List<UInt>
@ExperimentalUnsignedTypes fun ULongArray.takeLast( n: Int ): List<ULong>
@ExperimentalUnsignedTypes fun UByteArray.takeLast( n: Int ): List<UByte>
@ExperimentalUnsignedTypes fun UShortArray.takeLast( n: Int ): List<UShort>
Returns a list containing last n elements.
import kotlin.test.*
fun main(args: Array<String>) {
//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
}
IllegalArgumentException
- if n is negative.
© 2010–2019 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/take-last.html