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)
}
}
|
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
13 Aug, 2019
Like Article
Save Article