The dropWhile() method is utilized to drop the longest prefix of elements from the set that satisfies the stated condition.
Method Definition: def dropWhile(p: (A) => Boolean): Set[A]
Return Type: It returns a set containing all the elements after dropping the longest prefix of elements from the set that satisfies the stated condition.
Example #1:
// Scala program of dropWhile() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a list var s1 = Set(1, 3, 5, 4, 2) // Print the set println(s1) // Applying dropWhile method var res = s1.dropWhile(x => {x % 2 != 0}) // Displays output println(res) } } |
chevron_right
filter_none
Output:
Set(5, 1, 2, 3, 4) Set(2, 3, 4)
Example #2:
// Scala program of dropWhile() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a list var s1 = Set(1, 3, 5, 4, 2) // Print the set println(s1) // Applying dropWhile method var res = s1.dropWhile(x => true) // Displays output println(res) } } |
chevron_right
filter_none
Output:
Set(5, 1, 2, 3, 4) Set()
Recommended Posts:
- Scala Iterator dropWhile() method with example
- Scala Map dropWhile() method with example
- Scala List dropWhile() method with example
- Scala Queue dropWhile() method with example
- Scala SortedSet dropWhile() method with example
- Scala Stack dropWhile() method with example
- Scala TreeSet dropWhile() method with example
- Scala SortedMap dropWhile() method with example
- Scala Mutable SortedMap dropWhile() method with example
- Scala BitSet dropWhile() method with example
- Scala immutable TreeSet dropWhile() method
- Scala Mutable SortedSet dropWhile()
- Scala Set &() method with example
- Scala Set dropRight() method with example
- Scala Set equals() method with example
- Scala Set drop() method with example
- Scala Set diff() method with example
- Scala Set copyToArray() method with example
- Scala Set subsetOf() method with example
- Scala Set ++() 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.

