Repeated parameters

Scala allows you to indicate that the last parameter to a function may be repeated. This allows clients to pass variable length argument lists to the function. To denote a repeated parameter, place an asterisk after the type of the parameter. For example:
  scala> def echo(args: String*) = 
           for (arg <- args) println(arg)
  echo: (String*)Unit
Defined this way, echo can be called with zero to many String arguments:
  scala> echo()
  scala> echo("one")
  scala> echo("hello", "world!")
Read more: Repeated parameters

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Scala snippets
Sign Up Now
or Subscribe for future quizzes