Open In App

Scala BitSet dropWhile() method with example

Last Updated : 04 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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)


Similar Reads

Scala Set dropWhile() method with example
The dropWhile() method is utilized to drop the longest prefix of elements from the set that satisfies the stated condition. Method Definition: def dropWhile(p: (A) => Boolean): Set[A] Return Type: It returns a set containing all the elements after dropping the longest prefix of elements from the set that satisfies the stated condition. Example #
1 min read
Scala Iterator dropWhile() method with example
The dropWhile() method belongs to the concrete value members of the class Abstract Iterator. It is defined in the classes Iterator and IterableOnceOps. It drops the longest prefix of elements which satisfies the stated predicate. Method Definition : def dropWhile(p: (A) => Boolean): Iterator[A] Where, p is the predicate to be used. Return Type :
1 min read
Scala Map dropWhile() method with example
The dropWhile() method is utilized to delete the elements until the stated condition is satisfied. Method Definition: def dropWhile(p: ((A, B)) => Boolean): Map[A, B] Return Type: It returns the longest suffix of elements of the stated map whose first element does not satisfies the predicate p. Example #1: // Scala program of dropWhile() // meth
1 min read
Scala List dropWhile() method with example
The dropWhile() method is utilized to drops the longest prefix of elements that satisfies the stated condition. Method Definition: def dropWhile(p: (A) => Boolean): List[A] Return Type: It returns all the elements of the list except the dropped ones. Example #1: // Scala program of dropWhile() // method // Creating object object GfG { // Main me
1 min read
Scala Queue dropWhile() method with example
The dropWhile() method is utilized to drop the longest prefix from the front which satisfies a given predicate in a queue. Method Definition: def dropWhile(p: (A) => Boolean): Queue[A] Return Type: It returns a new queue that consists of elements after dropping the longest prefix satisfying the given predicate. Example #1: // Scala program of dr
2 min read
Scala SortedSet dropWhile() method with example
The dropWhile() method is utilized to drop the longest prefix of elements from the SortedSet that satisfies the stated condition. Method Definition: def dropWhile(p: (A) => Boolean): SortedSet[A] Return Type: It returns a TreeSet containing all the elements after dropping the longest prefix of elements from the SortedSet that satisfies the state
1 min read
Scala Stack dropWhile() method with example
In Scala Stack class, the dropWhile() method is utilized to drop the longest prefix from the top which satisfies a given predicate in a stack. Method Definition: def dropWhile(p: (A) => Boolean): Stack[A] Return Type: It returns a new stack that consists of elements after dropping the longest prefix satisfying the given predicate. Example #1: //
2 min read
Scala TreeSet dropWhile() method with example
In Scala TreeSet class, the dropWhile() method is utilized to drop the longest prefix from the front which satisfies a given predicate in a TreeSet. Method Definition: def dropWhile(p: (A) => Boolean): TreeSet[A] Return Type: It returns a new TreeSet that consists of elements after dropping the longest prefix satisfying the given predicate. Exam
2 min read
Scala SortedMap dropWhile() method with example
The dropWhile() method is utilized to delete the elements until the stated condition is satisfied. Method Definition: def dropWhile(p: ((A, B)) => Boolean): SortedMap[A, B] Return Type: It returns the longest suffix of elements of the stated SortedMap whose first element does not satisfies the predicate p. Example #1: // Scala program of dropWhi
1 min read
Scala Mutable SortedMap dropWhile() method with example
The dropWhile() method is utilized to delete the elements until the stated condition is satisfied. Method Definition: def dropWhile(p: ((A, B)) => Boolean): SortedMap[A, B] Return Type: It returns the longest suffix of elements of the stated SortedMap whose first element does not satisfies the predicate p. Example #1: // Scala program of dropWhi
1 min read