Languages
[Edit]
EN

Java - combine multiple lists

5 points
Created by:
Root-ssh
177980

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]
    }
}

Alternative titles

  1. Java - join multiple lists
  2. Java - concat multiple lists
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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