Functions - Variable number of arguments

Originally published at: http://www.itversity.com/topic/functions-variable-number-of-arguments/

Let us explore about variable number of arguments to a function. It is commonly known as varargs Typically a function with fixed set of arguments is declared as def add(arg1: Int, arg2: Int) = arg1 + arg2 A function with variable number of arguments is declared as def add(args: Int*) = args.toList.sum In the above…

1 Like