learning scala How To Create Variable Argument Function - varargs :_ *
Scala collection such as List or Sequence or even an Array to variable argument function using the syntax :_ *.
code :
def printReport(names: String*) { println(s"""Donut Report = ${names.mkString(" - ")}""") } println("\nStep 3: How to pass a List to a function with variable number of arguments") val listDonuts: List[String] = List("Glazed Donut", "Strawberry Donut", "Vanilla Donut") printReport(listDonuts: _*)
result:
Step 3: How to pass a List to a function with variable number of arguments Donut Report = Glazed Donut - Strawberry Donut - Vanilla Donut