Java examples for java.util:List Operation
Add a varargs list of items to the specified list.
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { public static final <T, U extends T> List<T> addToList(List<T> list, U... items) {// w ww . j ava 2 s . co m if (list != null && items != null) { for (int i = 0; i < items.length; i++) { list.add(items[i]); } if (list instanceof ArrayList) { ((ArrayList<T>) list).trimToSize(); } } return list; } public static final <T, U extends T> List<T> addToList(List<T> list, List<U> items) { if (list != null && items != null) { list.addAll(items); } return list; } }