splitAt()方法用於在給定位置將給定集合拆分為前綴/後綴對。
函數定義: def splitAt(n: Int): (Set[A], Set[A])
Where, n is the position at which we need to split.返回類型: It returns a pair of sets consisting of the first n elements of this set, and the other elements.
範例1:
// Scala program of splitAt()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a set
val s1 = Set(4, 12, 2, 31)
// Applying splitAt method
val result = s1.splitAt(2)
// Display output
println(result)
}
}
輸出:
(Set(4, 12), Set(2, 31))
範例2:
// Scala program of splitAt()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a set
val s1 = Set(1, 2, 3, 4)
// Applying splitAt method
val result = s1.splitAt(2)
// Display output
println(result)
}
}
輸出:
(Set(1, 2),Set(3, 4))
相關用法
- Scala TreeSet splitAt()用法及代碼示例
- Scala Stack splitAt()用法及代碼示例
- Scala List splitAt()用法及代碼示例
- Scala SortedSet splitAt()用法及代碼示例
- Scala Queue splitAt()用法及代碼示例
- Scala Set take()用法及代碼示例
- Scala Map take()用法及代碼示例
- Scala map()用法及代碼示例
- Scala Map max()用法及代碼示例
- Scala Int to(end: Int)用法及代碼示例
- Scala Set last()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 Scala Set splitAt() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。