By Alvin Alexander. Last updated: November 25, 2020
As a brief note, if you need to use a varargs parameter with a Scala method, and those varargs parameters should be added to an ArrayBuffer, I can confirm that this code works with Scala 2.13:
import scala.collection.mutable.ArrayBuffer val xs = ArrayBuffer[String]() // add one element to the ArrayBuffer xs += "a" // ArrayBuffer(a) // now create a method with a varargs parameter def appendStrings(strings: ArrayBuffer[String], varargsStrings: String*): Unit = xs.appendAll(varargsStrings) // now add multiple varargs parameters to the ArrayBuffer appendStrings(xs, "b", "c") xs // ArrayBuffer(a, b, c)
I just confirmed that this code works with Scala 2.13 and Scala 3.0.0