head

inline fun <T> Array<T>.head(n: Int = 10): List<T>

Returns a list containing first n elements.

Example:

arrayOf(1..10).head(3) // [1, 2, 3]

Since

1.1.0

Return

sublist

Parameters

n

number of elements return

See also

take
Array

Throws

IllegalArgumentException

if n is negative.


@JvmOverloads
fun ByteArray.head(n: Int = 10): List<Byte>

Returns a list containing first n elements.

Example:

byteArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).head(3) // [1, 2, 3]

Since

1.1.0

Return

sublist

Parameters

n

number of elements return

See also

take
byteArrayOf

Throws

IllegalArgumentException

if n is negative.


@JvmOverloads
fun CharArray.head(n: Int = 10): List<Char>

Returns a list containing first n elements.

Example:

charArrayOf('a'..'z').head(3) // ['a', 'b', 'c']

Since

1.1.0

Return

sublist

Parameters

n

number of elements return

See also

Throws

IllegalArgumentException

if n is negative.


@JvmOverloads
fun ShortArray.head(n: Int = 10): List<Short>

Returns a list containing first n elements.

Example:

shortArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).head(3) // [1, 2, 3]

Since

1.1.0

Return

sublist

Parameters

n

number of elements return

See also

take
shortArrayOf

Throws

IllegalArgumentException

if n is negative.


@JvmOverloads
fun IntArray.head(n: Int = 10): List<Int>

Returns a list containing first n elements.

Example:

intArrayOf(1..10).head(3) // [1, 2, 3]

Since

1.1.0

Return

sublist

Parameters

n

number of elements return

See also

Throws

IllegalArgumentException

if n is negative.


@JvmOverloads
fun LongArray.head(n: Int = 10): List<Long>

Returns a list containing first n elements.

Example:

longArrayOf(1..10L).head(3) // [1L, 2L, 3L]

Since

1.1.0

Return

sublist

Parameters

n

number of elements return

See also

Throws

IllegalArgumentException

if n is negative.


@JvmOverloads
fun FloatArray.head(n: Int = 10): List<Float>

Returns a list containing first n elements.

Example:

floatArrayOf(1F, 2F, 3F, 4F, 5F, 6F, 7F, 8F, 9F, 10F).head(3) // [1F, 2F, 3F]

Since

1.1.0

Return

sublist

Parameters

n

number of elements return

See also

take
floatArrayOf

Throws

IllegalArgumentException

if n is negative.


@JvmOverloads
fun DoubleArray.head(n: Int = 10): List<Double>

Returns a list containing first n elements.

Example:

doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0).head(3) // [1.0, 2.0, 3.0]

Since

1.1.0

Return

sublist

Parameters

n

number of elements return

See also

take
doubleArrayOf

Throws

IllegalArgumentException

if n is negative.


@JvmOverloads
fun BooleanArray.head(n: Int = 10): List<Boolean>

Returns a list containing first n elements.

Example:

booleanArrayOf(true, false, true, false, true).head(3) // [true, false, true]

Since

1.1.0

Return

sublist

Parameters

n

number of elements return

See also

take
booleanArrayOf

Throws

IllegalArgumentException

if n is negative.


inline fun <T> Iterable<T>.head(n: Int = 10): List<T>

Returns a list containing first n elements.

Example:

listOf(1..10).head(3) // [1, 2, 3]

Since

1.1.0

Return

sublist

Parameters

n

number of elements return

See also

take

Throws

IllegalArgumentException

if n is negative.