Scala Set splitAt() method with example
Last Updated :
18 Oct, 2019
The splitAt() method is utilized to split the given set into a prefix/suffix pair at a stated position.
Method Definition: def splitAt(n: Int): (Set[A], Set[A])
Where, n is the position at which we need to split.
Return Type: It returns a pair of sets consisting of the first n elements of this set, and the other elements.
Example #1:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 4 , 12 , 2 , 31 )
val result = s 1 .splitAt( 2 )
println(result)
}
}
|
Output:
(Set(4, 12), Set(2, 31))
Example #2:
object GfG
{
def main(args : Array[String])
{
val s 1 = Set( 1 , 2 , 3 , 4 )
val result = s 1 .splitAt( 2 )
println(result)
}
}
|
Output:
(Set(1, 2),Set(3, 4))
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...