Kotlin Program to Join Two Lists

Kotlin Program to Join Two Lists. You will see how to merge two or more collections into one. However, before we move ahead, we need to understand the difference between mutable and immutable types.

Kotlin Program to Join Two Lists

Source Code

import java.util.ArrayList

fun main(args: Array<String>) {

    val list1 = ArrayList<String>()
    list1.add("a")

    val list2 = ArrayList<String>()
    list2.add("b")

    val joined = ArrayList<String>()

    joined.addAll(list1)
    joined.addAll(list2)

    println("list1: $list1")
    println("list2: $list2")
    println("joined: $joined")

}

Output