我一直在寻找关于如何转换 ArrayBuffer
的一些时间。到 Set
, HashSet
我想准确的说。任何提示?
最佳答案
有一个toSet
函数在 ArrayBuffer 中实现
例子:
scala> import collection.mutable.ArrayBuffer
import collection.mutable.ArrayBuffer
scala> import collection.immutable.HashSet
import collection.immutable.HashSet
scala> val a = new ArrayBuffer(2)
a: scala.collection.mutable.ArrayBuffer[Nothing] = ArrayBuffer()
scala> val b = a.toSet
b: scala.collection.immutable.Set[Nothing] = Set()
关于scala:如何将 ArrayBuffer 转换为 Set?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9104249/