dropLast

fun <T> Array<out T>.dropLast(n: Int): List<T>
fun ByteArray.dropLast(n: Int): List<Byte>
fun ShortArray.dropLast(n: Int): List<Short>
fun IntArray.dropLast(n: Int): List<Int>
fun LongArray.dropLast(n: Int): List<Long>
fun FloatArray.dropLast(n: Int): List<Float>
fun DoubleArray.dropLast(n: Int): List<Double>
fun BooleanArray.dropLast(n: Int): List<Boolean>
fun CharArray.dropLast(n: Int): List<Char>
fun <T> List<T>.dropLast(n: Int): List<T>

Returns a list containing all elements except last n elements.

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val chars = ('a'..'z').toList()
assertPrints(chars.drop(23), "[x, y, z]")
assertPrints(chars.dropLast(23), "[a, b, c]")
assertPrints(chars.dropWhile { it < 'x' }, "[x, y, z]")
assertPrints(chars.dropLastWhile { it > 'c' }, "[a, b, c]") 
   //sampleEnd
}

Throws


fun UIntArray.dropLast(n: Int): List<UInt>
fun ULongArray.dropLast(n: Int): List<ULong>
fun UByteArray.dropLast(n: Int): List<UByte>
fun UShortArray.dropLast(n: Int): List<UShort>

Returns a list containing all elements except last n elements.

Since Kotlin

1.3

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val chars = ('a'..'z').toList()
assertPrints(chars.drop(23), "[x, y, z]")
assertPrints(chars.dropLast(23), "[a, b, c]")
assertPrints(chars.dropWhile { it < 'x' }, "[x, y, z]")
assertPrints(chars.dropLastWhile { it > 'c' }, "[a, b, c]") 
   //sampleEnd
}

Throws