Scala Set dropWhile() method with example
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:
object GfG
{
def main(args : Array[String])
{
var s 1 = Set( 1 , 3 , 5 , 4 , 2 )
println(s 1 )
var res = s 1 .dropWhile(x => {x % 2 ! = 0 })
println(res)
}
}
|
Output:
Set(5, 1, 2, 3, 4)
Set(2, 3, 4)
Example #2:
object GfG
{
def main(args : Array[String])
{
var s 1 = Set( 1 , 3 , 5 , 4 , 2 )
println(s 1 )
var res = s 1 .dropWhile(x => true )
println(res)
}
}
|
Output:
Set(5, 1, 2, 3, 4)
Set()
Last Updated :
15 Oct, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...