functionscalaarguments

Break array and pass as arguments in scala


I am new to scala so forgive me if this is easy to do.

I have an array consisting of values that I need to pass to a function. But the function accepts multiple arguments. The arguments are present but how do I break the array and pass it to the function?

In short I have array [1,2,3] and I want to call func(1,2,3).


Solution

  • Found it. For def func(a: Int*) it can be done with:

    func(arr:_*)