Scala Iterator duplicate() method with example Last Updated : 28 May, 2019 Comments Improve Suggest changes Like Article Like Report 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 // 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) } } Output: (non-empty iterator, non-empty iterator) Here, the stated iterator is non-empty so, two non-empty iterators are created. Example : Scala // 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) } } Output: (empty iterator, empty iterator) Here, the stated iterator is empty so, two empty iterators are created. Comment More infoAdvertise with us Next Article Scala Iterator duplicate() method with example N nidhi1352singh Follow Improve Article Tags : Scala Scala Scala-Method Similar Reads Scala Iterator drop() method with example 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 : de 2 min read Scala Iterator count() method with example The count() method belongs to the concrete value members of the class Abstract Iterator. It is defined in the class IterableOnceOps. It counts the number of elements in the stated collection which satisfy the given predicate. Method Definition : def count(p: (A) => Boolean): Int Where, p is the p 1 min read Scala Iterator buffered() method with example The buffered() method in Scala belongs to the concrete value members of the class iterator of Scala. It creates a buffered iterator from the iterator stated. Method Definition: def buffered: BufferedIterator[A] Return Type: It returns a buffered iterator which produces the alike values as the stated 1 min read Scala Iterator addString() method with example The addString() method belongs to the concrete value members of the class AbstractIterator. It is defined in the class IterableOnceOps. It is utilized to append the elements of the Scala Iterator to a String Builder. Method Definition : def addString(b: StringBuilder): StringBuilder Return Type : It 1 min read Scala Map iterator method with example The iterator method is utilized to give an iterator. Method Definition: def iterator: Iterator[(A, B)] Return Type: It returns a non-empty iterator for non-empty map and returns an empty iterator for empty map. Example #1: Scala // Scala program of iterator // method // Creating object object GfG { 1 min read Like