: _* notation in scala

Viewed 8339

I am encountering this : _* notation in many spark-scala answers, but couldn't find any documentation. What does it mean actually? An example of such usage is in the answer to this question

How to use DataFrame filter with isin in Spark Java?

line:

df.filter(col("something").isin(list: _*)
1 Answers

To understand it, lets take an example

scala> def echo(args: String*) =
for (arg <- args) println(arg)
echo: (args: String*)Unit

scala>  val arr = Array("What's", "up", "doc?")
arr: Array[String] = Array(What's, up, doc?)

scala> echo(arr)
<console>:14: error: type mismatch;
 found   : Array[String]
 required: String
       echo(arr)
scala> echo(arr: _ *)
What's
up
doc?

This notation,arr:_* tells the compiler to pass each element of arr as its own argument to echo , rather than all of it as a single argument.

Related