Scala Mutable SortedSet splitAt() 方法
在 Scala 可变集合中, splitAt()方法用于将给定的 SortedSet 拆分为指定位置的前缀/后缀对。
Method Definition: def splitAt(n: Int): (SortedSet[A], SortedSet[A])
Where, n is the position at which we need to split.
Return Type: It returns a pair of TreeSets consisting of the first n elements of this SortedSet, and the other elements.
示例 #1:
// Scala program of splitAt()
// method
import scala.collection.mutable.SortedSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a SortedSet
val s1 = SortedSet(2, 4, 11, 31)
// Applying splitAt method
val result = s1.splitAt(2)
// Display output
println(result)
}
}
输出:
(TreeSet(2, 4), TreeSet(11, 31))
示例 #2:
// Scala program of splitAt()
// method
import scala.collection.mutable.SortedSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a SortedSet
val s1 = SortedSet(1, 2, 3, 4)
// Applying splitAt method
val result = s1.splitAt(2)
// Display output
println(result)
}
}
输出:
(TreeSet(1, 2), TreeSet(3, 4))