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 objectobject 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) }} |
Output:
List(4, 2)
Example #2:
// Scala program of dropWhile()// method // Creating objectobject 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) }} |
Output:
List(5, 4, 2)


