Skip to content
Related Articles

Related Articles

Improve Article

Scala BitSet dropWhile() method with example

  • Last Updated : 04 May, 2020
Geek Week

Scala Bitsets are sets of non-negative integers which are represented as variable-size arrays of bits packed into 64-bit words. The drop() method is utilised to drop longest prefix of elements that satisfy a predicate.

Method Definition: def drop()

Return Type: It returns the longest suffix of collection whose first element does not satisfy p.

Example #1:




// Scala program of dropWhile() 
// method 
import scala.collection.immutable.BitSet 
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating a list 
        var s1 = BitSet(1, 3, 5, 4, 2
          
        // Print the BitSet 
        println(s1
          
        // Applying dropWhile method 
        var res = s1.dropWhile(x => {x % 2 != 0}) 
          
        // Displays output 
        println(res) 
      
    
Output:
BitSet(1, 2, 3, 4, 5)
BitSet(2, 3, 4, 5)

Example #2:




// Scala program of dropWhile() 
// method 
import scala.collection.immutable.BitSet 
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating a list  
        var s1 = BitSet(15, 17, 21)  
            
        // Print the BitSet
        println(s1
            
        // Applying dropWhile method  
        var res = s1.dropWhile(x => {x % 3 == 0})  
          
        // Displays output 
        println(res) 
      
    
Output:
BitSet(15, 17, 21)
BitSet(17, 21)



My Personal Notes arrow_drop_up
Recommended Articles
Page :