Scala BitSet dropWhile() method with example
Scala Bitsets are sets of non-negative integers which are represented as variable-size arrays of bits packed into 64-bit words. The drop() method is utilised to drop longest prefix of elements that satisfy a predicate.
Method Definition: def drop()
Return Type: It returns the longest suffix of collection whose first element does not satisfy p.
Example #1:
import scala.collection.immutable.BitSet
object GfG
{
def main(args : Array[String])
{
var s 1 = BitSet( 1 , 3 , 5 , 4 , 2 )
println(s 1 )
var res = s 1 .dropWhile(x => {x % 2 ! = 0 })
println(res)
}
}
|
Output:
BitSet(1, 2, 3, 4, 5)
BitSet(2, 3, 4, 5)
Example #2:
import scala.collection.immutable.BitSet
object GfG
{
def main(args : Array[String])
{
var s 1 = BitSet( 15 , 17 , 21 )
println(s 1 )
var res = s 1 .dropWhile(x => {x % 3 == 0 })
println(res)
}
}
|
Output:
BitSet(15, 17, 21)
BitSet(17, 21)
Last Updated :
04 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...