Scala TreeSet clone() method with example
Last Updated :
02 Nov, 2019
In Scala TreeSet class
, the clone() method is used to create a copy of the given TreeSet.
Method Definition: def clone(): Queue[A]
Return Type: It return a new TreeSet which is a copy of the given TreeSet.
Example #1:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( 2 , 1 , 3 , 4 , 5 )
println(t 1 )
val result = t 1 .clone
println( "Clone of the TreeSet: " + result)
}
}
|
Output:
TreeSet(1, 2, 3, 4, 5)
Clone of the TreeSet: TreeSet(1, 2, 3, 4, 5)
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( "a" , "e" , "i" , "o" , "u" )
println(t 1 )
val result = t 1 .clone
println( "Clone of the TreeSet: " + result)
}
}
|
Output:
TreeSet(a, e, i, o, u)
Clone of the TreeSet: TreeSet(a, e, i, o, u)
Share your thoughts in the comments
Please Login to comment...