Example 1 — Merge Two Lists into One
Start with one list of weekday names and add a second list to the end of it.
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
public class LinkedListAddAllMerge {
public static void main(String[] args) {
LinkedList<String> days = new LinkedList<>();
days.add("Mon");
days.add("Tue");
List<String> more = Arrays.asList("Wed", "Thu", "Fri");
boolean changed = days.addAll(more);
System.out.println("days: " + days);
System.out.println("changed: " + changed);
System.out.println("source untouched: " + more);
}
} How It Works
- A starting list.
daysholds Mon and Tue. - Whole group appended. Wed, Thu and Fri are added after Tue, in the same order as in
more. - The list changed. At least one element was added, so
addAllreturns true. - The source stays the same.
moreis only read, never modified.

