Scala Iterator zip() method with example
The zip() method belongs to the concrete value member of the class Abstract Iterator. It is defined in the class Iterator.
Method Definition: val result = iter.zip(iter1)
Return Type: It returns a new Scala iterator holding pairs of corresponding elements in the iterator and the size of the number of elements returned is minimum of the sizes of both the iterators.
Example #1:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 1 , 2 , 3 , 4 , 5 , 6 )
val iter 1 = Iterator( 7 , 8 , 9 , 10 )
val result = iter.zip(iter 1 )
println(result)
}
}
|
Output:
non-empty iterator
Example #2:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator()
val iter 1 = Iterator( 0 , 0 , 0 , 0 )
val result = iter.zip(iter 1 )
println(result)
}
}
|
Last Updated :
13 Aug, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...