Scala List dropWhile() method with example
The dropWhile() method is utilized to drops the longest prefix of elements that satisfies the stated condition.
Method Definition: def dropWhile(p: (A) => Boolean): List[A]
Return Type: It returns all the elements of the list except the dropped ones.
Example #1:
// Scala program of dropWhile() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a list val m1 = List(1, 3, 5, 4, 2) // Applying dropWhile method val res = m1.dropWhile(x=>{x % 2 != 0}) // Displays output println(res) } } |
chevron_right
filter_none
Output:
List(4, 2)
Example #2:
// Scala program of dropWhile() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a list val m1 = List(3, 6, 5, 4, 2) // Applying dropWhile method val res = m1.dropWhile(x=>{x % 3 == 0}) // Displays output println(res) } } |
chevron_right
filter_none
Output:
List(5, 4, 2)
Recommended Posts:
- Scala Map dropWhile() method with example
- Scala Set dropWhile() method with example
- Scala Queue dropWhile() method with example
- Scala Iterator dropWhile() method with example
- Scala Stack dropWhile() method with example
- Scala SortedMap dropWhile() method with example
- Scala TreeSet dropWhile() method with example
- Scala SortedSet dropWhile() method with example
- Scala List take() method with example
- Scala List map() method with example
- Scala List contains() method with example
- Scala List sum() method with example
- Scala List min() method with example
- Scala List max() method with example
- Scala List size() 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.



