Scala BitSet ++[B](that: GenTraversableOnce[B]) method with example
Last Updated :
04 May, 2020
Scala Bitsets are sets of non-negative integers which are represented as variable-size arrays of bits packed into 64-bit words. The ++[B](that: GenTraversableOnce[B])
method is utilised create a bitset containing the elements from the left hand operand followed by the elements from the right hand operand.
Method Definition: def ++[B](that: GenTraversableOnce[B])
Return Type: It returns a new bitset which contains all elements of this bitset.
Example #1:
import scala.collection.immutable.BitSet
object GfG
{
def main(args : Array[String])
{
val b 1 : BitSet = BitSet( 0 , 1 , 2 , 3 )
val b 2 = List( "a" , "B" )
val bs 1 = b 1 ++ b 2
println(bs 1 )
}
}
|
Output:
Set(0, 1, a, 2, B, 3)
Example #2:
import scala.collection.immutable.BitSet
object GfG
{
def main(args : Array[String])
{
val b 1 : BitSet = BitSet( 0 , 1 , 2 , 3 )
val b 2 = List( "A" )
val bs 1 = b 1 ++ b 2
println(bs 1 )
}
}
|
Output:
Set(0, 1, A, 2, 3)
Share your thoughts in the comments
Please Login to comment...