dropLast

Common
JVM
JS
Native
1.0
fun <T> Array<out T>.dropLast(n: Int): List<T>
(source)
fun ByteArray.dropLast(n: Int): List<Byte>
(source)
fun ShortArray.dropLast(n: Int): List<Short>
(source)
fun IntArray.dropLast(n: Int): List<Int>
(source)
fun LongArray.dropLast(n: Int): List<Long>
(source)
fun FloatArray.dropLast(n: Int): List<Float>
(source)
fun DoubleArray.dropLast(n: Int): List<Double>
(source)
fun BooleanArray.dropLast(n: Int): List<Boolean>
(source)
fun CharArray.dropLast(n: Int): List<Char>
(source)
fun <T> List<T>.dropLast(n: Int): List<T>
(source)
@ExperimentalUnsignedTypes fun UIntArray.dropLast(
    n: Int
): List<UInt>

(source)
@ExperimentalUnsignedTypes fun ULongArray.dropLast(
    n: Int
): List<ULong>

(source)
@ExperimentalUnsignedTypes fun UByteArray.dropLast(
    n: Int
): List<UByte>

(source)
@ExperimentalUnsignedTypes fun UShortArray.dropLast(
    n: Int
): List<UShort>

(source)

Returns a list containing all elements except last n elements.

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val chars = ('a'..'z').toList()
println(chars.drop(23)) // [x, y, z]
println(chars.dropLast(23)) // [a, b, c]
println(chars.dropWhile { it < 'x' }) // [x, y, z]
println(chars.dropLastWhile { it > 'c' }) // [a, b, c]
//sampleEnd
}

Exceptions

IllegalArgumentException - if n is negative.