Tsallaka zuwa abun ciki
Justice Tech School

vararg

vararg accepts any number of arguments as an array. Spread an array with *.

Example
fun sum(vararg n: Int) = n.sum()
println(sum())
println(sum(1, 2, 3))
val a = intArrayOf(4, 5)
println(sum(*a))

Exercise

Spread an array.

sum(a)

Quiz Test

What type is n inside?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.