Scala Iterator duplicate() method with example
Last Updated :
28 May, 2019
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.
Example :
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 3 , 4 , 5 , 7 , 8 )
val iter 1 = iter.duplicate
println(iter 1 )
}
}
|
Output:
(non-empty iterator, non-empty iterator)
Here, the stated iterator is non-empty so, two non-empty iterators are created.
Example :
object GfG
{
def main(args : Array[String])
{
val iter = Iterator()
val iter 1 = iter.duplicate
println(iter 1 )
}
}
|
Output:
(empty iterator, empty iterator)
Here, the stated iterator is empty so, two empty iterators are created.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...