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:
// 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) } } |
chevron_right
filter_none
Output:
(Set(4, 12), Set(2, 31))
Example #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) } } |
chevron_right
filter_none
Output:
(Set(1, 2),Set(3, 4))
Recommended Posts:
- Scala TreeSet splitAt() method with example
- Scala List splitAt() method with example
- Scala SortedSet splitAt() method with example
- Scala Queue splitAt() method with example
- Scala Stack splitAt() method with example
- Scala Mutable SortedSet splitAt() method
- Scala immutable TreeSet splitAt() method
- Scala Set last() method with example
- Scala Map last() method with example
- Scala Int until(end: Int) method with example
- Scala Set map() method with example
- Scala Int ==(x: Int) method with example
- Scala Int -(x: Int) method with example
- Scala Int >>(x: Int) method with example
- Scala Int abs() method with example
- Scala Int *(x: Int) method with example
- Scala Int >>>(x: Int) method with example
- Scala Int <(x: Int) method with example
- Scala Set ++() method with example
- Scala Int +(x: Int) method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

