BitSet DropRight() Method in Scala with Example

Here, we will learn about BitSet dropRight() method in Scala. It is used to drop n elements from right. We will learn about dropRight() method in Scala with syntax and examples.
Submitted by Shivang Yadav, on December 04, 2020

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.

Program 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]) {
        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)

Program 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]) {
        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()




Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.