Scala immutable TreeSet drop() method
Last Updated :
19 Apr, 2020
In Scala immutable TreeSet class
, the drop() method is utilized to drop the first ‘n’ elements of the TreeSet.
Method Definition: def drop(n: Int): TreeSet[A]
Return Type: It returns a new TreeSet with all the elements except the first ‘n’ ones.
Example #1:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( 2 , 4 , 6 , 7 , 8 , 9 )
println(t 1 )
val result = t 1 .drop( 2 )
println( "TreeSet after using drop(2) method: " + result)
}
}
|
Output:
TreeSet(2, 4, 6, 7, 8, 9)
TreeSet after using drop(2) method: TreeSet(6, 7, 8, 9)
Example #2:
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val t 1 = TreeSet( 2 , 4 , 6 , 7 , 8 , 9 )
println(t 1 )
val result = t 1 .drop( 3 )
println( "TreeSet after using drop(3) method: " + result)
}
}
|
Output:
TreeSet(2, 4, 6, 7, 8, 9)
TreeSet after using drop(3) method: TreeSet(7, 8, 9)
Share your thoughts in the comments
Please Login to comment...