4

I have a function in Scala that requires a String vararg, i.e. String*. How can I call that function if I have an Array[String]?

1
  • 2
    A word of notation: String * isn't a type, so "convert to String *" doesn't really make sense. The question here is how to call a varargs function with an Array. Commented Jan 31, 2016 at 5:52

1 Answer 1

5

You can use : _* for that

def f(strings: String*) {
  ...
}

f(Array("a", "b", "c"): _*)
Sign up to request clarification or add additional context in comments.

2 Comments

no `: _*' annotation allowed here (such annotations are only allowed in arguments to *-parameters)
Sorry, I made a mistake.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.