Scala BitSet –() 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 –() method is utilised create a new collection from this collection by removing all elements of another collection.
Method Definition: def –()
Return Type: It returns a new collection that contains all elements of the current collection except elems.
Example #1:
import scala.collection.immutable.BitSet
object GfG
{
def main(args : Array[String])
{
val b 1 : BitSet = BitSet( 0 , 1 , 2 , 3 , 4 , 5 )
val b 2 : BitSet = BitSet( 4 , 5 )
val bs 1 : BitSet = b 1 -- b 2
println(bs 1 )
}
}
|
Output:
BitSet(0, 1, 2, 3)
Example #2:
import scala.collection.immutable.BitSet
object GfG
{
def main(args : Array[String])
{
val b 1 : BitSet = BitSet( 0 , 1 , 2 , 3 , 15 , 16 )
val b 2 : BitSet = BitSet( 15 , 16 , 0 )
val bs 1 : BitSet = b 1 -- b 2
println(bs 1 )
}
}
|
Last Updated :
04 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...