Home »
Scala
BitSet DropRight() Method in Scala
By IncludeHelp Last updated : November 14, 2024
BitSet in Scala is a special collection of positive integers. Scala programming language has a huge library containing a lot of utility functions to help working with data structure easy.
BitSet dropRight() method
BitSet dropRight() method is used to select all elements from the BitSet except last n elements i.e. deletes n elements from right.
Syntax
BitSet_Name.DropRight(n)
Parameters
The method accepts a single parameter which is the number of elements to be deleted.
Return Type
Returns a BitSet which is the contains all the selected elements.
Example 1
Program to illustrate the working of dropRight() method
// Program to illustrate the working of dropRight() method
import scala.collection.immutable.BitSet
object MyObject {
def main(args: Array[String]): Unit = {
val myBitset = BitSet(6, 1, 2, 9, 4, 8, 3)
println("myBitset : " + myBitset)
val newBitset = myBitset.dropRight(3)
println("myBitset after deleting 3 elements: " + newBitset)
}
}
Output
myBitset : BitSet(1, 2, 3, 4, 6, 8, 9)
myBitset after deleting 3 elements: BitSet(1, 2, 3, 4)
Example 2
Program to illustrate the working of dropRight() method when n is greater than the size of BitSet.
// Program to illustrate the working of dropRight() method
import scala.collection.immutable.BitSet
object MyObject {
def main(args: Array[String]): Unit = {
val myBitset = BitSet(6, 1, 2, 9, 4, 8, 3)
println("myBitset : " + myBitset)
val newBitset = myBitset.dropRight(10)
println("myBitset after deleting 10 elements: " + newBitset)
}
}
Output
myBitset : BitSet(1, 2, 3, 4, 6, 8, 9)
myBitset after deleting 10 elements: BitSet()