Languages
[Edit]
EN

Java - combine multiple lists

5 points
Created by:
Root-ssh
85030

In this short article we would like to show how to combine multiple lists into one list in Java.

Quick solution:

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Example {

    public static void main(String[] args) {

        List<String> a = Arrays.asList("a", "aa");
        List<String> b = Arrays.asList("b", "bb");
        List<String> c = Arrays.asList("c", "cc");

        List<String> combinedLists = new ArrayList<>();

        combinedLists.addAll(a);
        combinedLists.addAll(b);
        combinedLists.addAll(c);

        System.out.println(combinedLists.toString()); // [a, aa, b, bb, c, cc]
    }
}
Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join