gpt4 book ai didi

scala - 将不可变转换为可变集合

转载 作者:行者123 更新时间:2023-12-03 14:01:08 25 4
gpt4 key购买 nike

collection.immutable.Set转换为collection.mutable.Set的最佳方法是什么?

最佳答案

scala> var a=collection.mutable.Set[Int](1,2,3)                              
a: scala.collection.mutable.Set[Int] = Set(1, 2, 3)

scala> var b=collection.immutable.Set[Int](1,2,3)
b: scala.collection.immutable.Set[Int] = Set(1, 2, 3)

scala> collection.mutable.Set(b.toArray:_*)
res0: scala.collection.mutable.Set[Int] = Set(1, 2, 3)

scala> collection.mutable.Set(b.toSeq:_*)
res1: scala.collection.mutable.Set[Int] = Set(1, 2, 3)

scala> collection.mutable.Set(b.toList:_*)
res2: scala.collection.mutable.Set[Int] = Set(1, 2, 3)

关于scala - 将不可变转换为可变集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3178422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com