The drop() method belongs to the concrete value member of the class Abstract Iterator. It is defined in the classes Iterator and IterableOnceOps. It is utilized to move the iterator n places ahead and if n is greater than the iterator’s length, then it will throw an exception.
Method Definition : def drop(n: Int): Iterator[A]
Where, n is the number of elements to be dropped from the stated iterator.
Return Type : It returns all the elements of the stated iterator except the first n ones.
Example #1:
// Scala program of drop() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating an Iterator val iter = Iterator(4, 6, 10, 11, 13) // Applying drop method val x = iter.drop(4) // Applying next method val result = x.next() // Displays output println(result) } } |
13
Here, the first four elements are dropped and all the elements after that are returned.
Example #2:
// Scala program of drop() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating an Iterator val iter = Iterator(2, 3, 4) // Applying drop method val x = iter.drop(1) // Applying next method val result = x.next() // Displays output println(result) } } |
3
Recommended Posts:
- Scala Set drop() method with example
- Scala List drop() method with example
- Scala Map drop() method with example
- Scala Queue drop() method with example
- Scala SortedSet drop() method with example
- Scala Stack drop() method with example
- Scala TreeSet drop() method with example
- Scala SortedMap drop() method with example
- Scala Mutable SortedMap drop() method with example
- Scala BitSet drop() method with example
- Scala Iterator addString() method with example
- Scala Iterator slice() method with example
- Scala Iterator size() method with example
- Scala Iterator indexOf() method with example
- Scala Iterator isTraversableAgain() method with example
- Scala Iterator sameElements() method with example
- Scala Iterator indexWhere() method with example
- Scala Iterator hasDefiniteSize() method with example
- Scala Iterator buffered() method with example
- Scala Iterator duplicate() method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

