In this article, several methods to concatenate multiple lists into a single list in Kotlin.

1. Using flatten() function

A simple solution is to use the flatten() function, which returns a single list of all elements from the given sequence. The following example demonstrates its usage with the help of the Spread operator.

Download Code

2. Using Plus Operator

Another simple and fairly efficient solution to combine two or more lists is with the plus operator. This is demonstrated below:

Download Code

3. Using addAll() function

Alternatively, you can use the addAll() function that adds specified elements to the specified collection.

Download Code

 
You can also accumulate all elements using forEach(), as shown below:

Download Code

4. Using Double Brace Initialization

Although not recommended, the Double Brace Initialization technique can be used to concatenate multiple lists into a single list. It creates an anonymous inner class with an instance initializer in it.

Download Code

That’s all about concatenating multiple lists in Kotlin.