Kotlin Flatten List – Problem & Solution

In the tutorial, JavaSampleApproach will introduce Kotlin flatten() and the limit of the method. So we will provide a new Flatten Solution for Kotlin List.

I. Kotlin List flatten()

1. flatten() method

Kotlin provides a method to flatten a List:

-> Returns a single list of all elements from all collections in the given collection.


2. Problem

Problem 1

Problem 2

Why? -> Because the limit of Kotlin flatten()‘s implementation:

II. Implement new Flatten Solution

Implement a new flatten solution as below:

-> Test:

By JavaSampleApproach | February 4, 2018.

Related Posts

Got Something To Say:

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