learning scala How To Create Variable Argument Function

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("
Step 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
原文地址:https://www.cnblogs.com/lianghong881018/p/11171676.html