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:
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 1 , 3 , 5 , 4 , 2 )
val res = m 1 .dropWhile(x => {x % 2 ! = 0 })
println(res)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val m 1 = List( 3 , 6 , 5 , 4 , 2 )
val res = m 1 .dropWhile(x => {x % 3 == 0 })
println(res)
}
}
|