Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Java

Idiom #166 Concatenate two lists

Create the list ab containing all the elements of the list a, followed by all the elements of the list b.

var ab = new ArrayList<>(a);
ab.addAll(b);

The first line creates a new array list and puts all the elements from a inside it. The second line adds the b elements.
import java.util.ArrayList;
import java.util.List;
List<?> ab = new ArrayList<>(a) {{ addAll(b); }};
(def ab (concat a b))

New implementation...