This article explores different ways to join two lists in Kotlin.

1. Using Plus Operator

A simple solution to join two lists is with the plus operator. To illustrate, the following creates a new list, which is the concatenation of both lists.

Download Code

 
An equivalent way is to use the plus() function.

Download Code

2. Using addAll() function

Alternatively, you can use the native addAll() function, which appends all specified collection elements at the end of the list.

Download Code

 
You can also avoid the first call to the addAll() function by initializing the list with the first list using the ArrayList constructor.

Download Code

3. Using Double Brace Initialization

You can also use Double Brace Initialization, which internally creates an anonymous inner class with an instance initializer in it. We should avoid this approach.

Download Code

4. Using Java 8 Stream

You can also use Stream to join two lists, as shown below:

Download Code

That’s all about joining two lists in Kotlin.