take

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

Returns a list containing first 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
}