Scala 可变 SortedSet toSeq() 方法
在 Scala 可变集合中,SortedSet toSeq() 方法被用于返回由所有 SortedSet 元素组成的 seq 。
方法定义:def toSeq:Seq [A]
返回类型:它返回一个由 SortedSet 元素组成的 seq 。
示例 #1:
// Scala program of toSeq()
// method
import scala.collection.mutable.SortedSet
// 创建对象
object GfG
{
// Main method
def main(args:Array[String])
{
// 创建 SortedSet
val s1 = SortedSet(11, 12, 13, 14)
// 应用 toSeq 方法
val result = s1.toSeq
// 显示输出
for (ele <- result)
println(ele)
}
}
11
12
13
14
示例 #2:
// Scala program of toSeq()
// method
import scala.collection.mutable.SortedSet
// 创建对象
object GfG
{
// Main method
def main(args:Array[String])
{
// 创建 SortedSet
val s1 = SortedSet(4, 2, 3, 43, 11, 72)
// 应用 toSeq 方法
val result = s1.toSeq
// 显示输出
for (ele <- result)
println(ele)
}
}
2
3
4
11
43
72
阅读更多:Scala 教程
极客教程