Kotlin forEach & forEachIndexed method on Array, List, Map collection

In the tutorial, JavaSampleApproach will show you how to use Kotlin forEach and forEachIndexed methods to loop through Kotlin Array, List, Map collections.

I. forEach method

forEach method is used to performs the given action on each element.

1. with Array

Method signature:

Practice:

2. with List

Method signature:

Practice:

3. with Map

Method Signature:

Practice:

II. forEachIndexed method

forEachIndexed method performs the given action on each element, providing sequential index with the element.

1. with Array

Method Signature:

Practice:

2. with List

Method signature:

Practice:

III. Full sourcecode

By JavaSampleApproach | January 5, 2018.

Related Posts


Got Something To Say:

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

*