Scala immutable TreeSet ++() method
Last Updated :
19 Apr, 2020
In Scala immutable TreeSet class
, the ++() method is utilised to add elements of one TreeSet to another TreeSet.
Method Definition: def ++(that: IterableOnce[A]): TreeSet[A]
Return Type: It returns a new TreeSet which contains all the element from both the given TreeSets.
Example #1:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( "g" , "e" , "e" , "k" , "s" )
val t 2 = TreeSet( "a" , "e" , "i" , "o" , "u" )
println(t 1 )
println(t 2 )
val result = t 1 ++ t 2
print( "Combined TreeSet: " + result)
}
}
|
Output:
TreeSet(e, g, k, s)
TreeSet(a, e, i, o, u)
Combined TreeSet: TreeSet(a, e, g, i, k, o, s, u)
Example #2:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( 1 , 6 , 3 , 2 , 5 )
val t 2 = TreeSet( 2 , 1 , 5 , 4 , 1 )
println(t 1 )
println(t 2 )
val result = t 1 ++ t 2
print( "Combined TreeSet: " + result)
}
}
|
Output:
TreeSet(1, 2, 3, 5, 6)
TreeSet(1, 2, 4, 5)
Combined TreeSet: TreeSet(1, 2, 3, 4, 5, 6)
Share your thoughts in the comments
Please Login to comment...