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:

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

Sample:

2. zip() with transform function

Use below method signatures:

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

Sample:

II. zipWithNext() method

1. zipWithNext()

Method signature:

-> Returns a list of pairs of each two adjacent elements in this collection.

Sample:

2. zipWithNext() with transform function

Method signature:

-> Returns a list containing the results of applying the given transform function to an each pair of two adjacent elements in this collection.

Sample:

By JavaSampleApproach | February 25, 2018.

Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*