English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Scala Function Variable Parameters
Scala allows you to specify that the last parameter of a function can be repeated, that is, we do not need to specify the number of function parameters, and we can pass a variable length parameter list to the function.
object Test { def main(args: Array[String]) { printStrings("w3codebox, "Scala", "Python"); } def printStrings( args: String* ) = { var i: Int = 0; for( arg <- args ){ println("Arg value[" + i + "] = " + arg ); i = i + 1; } } }
Execute the above code, the output will be:
$ scalac Test.scala $ scala Test Arg value[0] = w3codebox Arg value[1] = Scala Arg value[2] = Python