DEV Community

loading...

Kotlin List – zip() + zipWithNext()

loizenai profile image loizenai ・1 min read

Kotlin List – zip() + zipWithNext()

https://grokonez.com/kotlin/kotlin-list-zip-zipwithnext

In the tutorial, we will show how to use zip() and zipWithNext() methods of Kotlin List collection.

I. zip() method

1. zip()

Use below method signatures:


infix fun  Iterable.zip(
    other: Array
): List>
infix fun  Iterable.zip(
    other: Iterable
): List>

-> Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.

Sample:

More at:

https://grokonez.com/kotlin/kotlin-list-zip-zipwithnext

Discussion (0)

pic
Editor guide