Scala BitSet diff() 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 diff() method is utilised to compute the difference of this set and another set.
Method Definition: def +()
Return Type: It returns a set containing diff elements
Example #1:
import scala.collection.immutable.BitSet
object GfG
{
def main(args : Array[String])
{
val s 1 = BitSet( 1 , 2 , 3 , 4 , 5 )
val s 2 = BitSet( 1 , 2 , 3 )
val s 3 = s 1 .diff(s 2 )
for (elem < - s 3 )
println(elem)
}
}
|
Example #2:
import scala.collection.immutable.BitSet
object GfG
{
def main(args : Array[String])
{
val s 1 = BitSet( 1 , 2 , 3 , 4 , 5 )
val s 2 = BitSet( 6 , 2 , 7 , 8 )
val s 3 = s 1 .diff(s 2 )
for (elem < - s 3 )
println(elem)
}
}
|
Last Updated :
04 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...