Scala Iterator duplicate() method with example
The duplicate() method belongs to the concrete value member of the class iterator. It generates a duplicate of the iterator which will iterate over the alike order of values. The duplicate iterators are said to be equal if they are put at the identical element.
-
Method Definition:
def duplicate: (Iterator[A], Iterator[A])
-
Return Type:
It returns a pair of iterators.
Example :
// Scala program of duplicate() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Declaring an iterator val iter = Iterator(3, 4, 5, 7, 8) // Applying duplicate method val iter1 = iter.duplicate // Displays output println(iter1) } } |
(non-empty iterator, non-empty iterator)
Here, the stated iterator is non-empty so, two non-empty iterators are created.
Example :
// Scala program of duplicate() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Declaring an empty-iterator val iter = Iterator() // Applying duplicate method val iter1 = iter.duplicate // Displays output println(iter1) } } |
(empty iterator, empty iterator)
Here, the stated iterator is empty so, two empty iterators are created.
Recommended Posts:
- Scala Iterator zip() method with example
- Scala Iterator map() method with example
- Scala Iterator next() method with example
- Scala Iterator sum() method with example
- Scala Iterator take() method with example
- Scala Iterator seq() method with example
- Scala Map iterator method with example
- Scala Iterator max() method with example
- Scala Iterator min() method with example
- Scala Iterator toBuffer() method with example
- Scala Iterator buffered() method with example
- Scala Iterator size() method with example
- Scala Iterator hasDefiniteSize() method with example
- Scala Iterator drop() method with example
- Scala Iterator mkString() 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.



