Scala BitSet ++:[B](that: TraversableOnce[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: TraversableOnce[B]) method is utilised create a collection containing the elements from the left hand operand followed by the elements from the right hand operand.
Method Definition: def ++:[B](that: TraversableOnce[B])
Return Type: It returns a new bitset which contains all elements of this bitset followed by all elements of that.
Example #1:
import scala.collection.immutable.BitSet
import scala.collection.mutable.LinkedList
object GfG
{
def main(args : Array[String])
{
val b 1 = BitSet( 0 , 1 , 2 , 3 )
val b 2 = LinkedList( 100 )
val bs 1 = b 1 ++ : b 2
println(bs 1 )
}
}
|
Output:
LinkedList(0, 1, 2, 3, 100)
Example #2:
import scala.collection.immutable.BitSet
import scala.collection.mutable.LinkedList
object GfG
{
def main(args : Array[String])
{
val b 1 = BitSet( 11 , 22 , 33 )
val b 2 = LinkedList( "A" , "B" )
val bs 1 = b 1 ++ : b 2
println(bs 1 )
}
}
|
Output:
LinkedList(0, 1, 2, 3, A, B)
Share your thoughts in the comments
Please Login to comment...