Tutorial by Examples

Define the function using the vararg keyword. fun printNumbers(vararg numbers: Int) { for (number in numbers) { println(number) } } Now you can pass as many parameters (of the correct type) into the function as you want. printNumbers(0, 1) // Prints "0&qu...
Arrays can be passed into vararg functions using the Spread Operator, *. Assuming the following function exists... fun printNumbers(vararg numbers: Int) { for (number in numbers) { println(number) } } You can pass an array into the function like so... val numbers = intArray...

Page 1 of 1