schmmd schmmd - 8 months ago 58
Scala Question

Convert an array to a mutable set in Scala?

How does one convert a Scala array to a mutable.Set? It's easy to convert to an immutable.Set

Array(1, 2, 3).toSet

But I can't find an obvious way to convert to a mutable.Set.

Answer Source
scala> scala.collection.mutable.Set( Array(1,2) :_* )
res2: scala.collection.mutable.Set[Int] = Set(2, 1)

The weird :_* type ascription, forces factory method to see the array as a list of arguments.