10

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: _*)
user3190018
  • 890
  • 13
  • 26
pasternak
  • 361
  • 4
  • 14
  • 5
    Possible duplicate of [How to pass Scala array into Scala vararg method?](https://stackoverflow.com/questions/31064753/how-to-pass-scala-array-into-scala-vararg-method) or [What does `:_*` (colon underscore star) do in Scala?](https://stackoverflow.com/questions/6051302/what-does-colon-underscore-star-do-in-scala) – Harald Gliebe Sep 25 '17 at 05:17
  • @pasternak : please see/check whether same kind of question was asked, which has answers... before you raise new question. – Ram Ghadiyaram Sep 25 '17 at 07:56

1 Answers1

23

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.

Ram Ghadiyaram
  • 28,239
  • 13
  • 95
  • 121
Mahesh Chand
  • 3,158
  • 19
  • 37