Home »
Scala
BitSet DropWhile() Method in Scala
By IncludeHelp Last updated : November 14, 2024
BitSet in Scala is a special collection of positive integers. Scala programming language has a huge library containing a lot of utility functions to help working with data structure easy.
BitSet dropWhile() method
BitSet dropWhile() method is used to delete the first element that satisfies the given condition and return the remaining BitSet.
Syntax
bitset_name.dropWhile(condition)
Parameters
It accepts a single parameter which is the condition to delete the element.
Return Type
Returns a BitSet which contains elements after deleting.
Example 1
Example to delete element from BitSet using dropWhile() method
// Program to illustrate the working of dropWhile() method
import scala.collection.immutable.BitSet
object MyObject {
def main(args: Array[String]): Unit = {
val myBitset = BitSet(8, 3, 6, 2, 9)
println("myBitset : " + myBitset)
val newBitset = myBitset.dropWhile(x => {x % 2 == 0} )
println("myBitset after deleting elements using dropWhile : " + newBitset)
}
}
Output
myBitset : BitSet(2, 3, 6, 8, 9)
myBitset after deleting elements using dropWhile : BitSet(3, 6, 8, 9)
Explanation
In the above code, we have created a BitSet named myBitset in Scala. Then dropped the first element which is even, then print the resulting BitSet.