Example usage for java.util List addAll

List of usage examples for java.util List addAll

Introduction

In this page you can find the example usage for java.util List addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

Usage

From source file:Main.java

public static void removeDuplicates(List list) {
    Set set = new LinkedHashSet(list);
    list.clear();//  www  .j ava2s . c o  m
    list.addAll(set);
}

From source file:dumpsection.util.Util.java

public static Set<Integer> stringArrayToUnsignedIntegerSet(String[] src, int radix) {
    Set<Integer> x = new HashSet<>();
    List<String> ls = new ArrayList<>();
    ls.addAll(Arrays.asList(src));
    for (String s : ls) {
        try {//from w  w w  . j  a  v  a2 s.com
            x.add(Integer.parseUnsignedInt(s, radix));
        } catch (NumberFormatException e) {
            throw e;
        }
    }
    return Collections.unmodifiableSet(x);
}

From source file:Main.java

public static <T> List<T> concat(List<T> list1, List<T> list2) {
    List<T> list = new ArrayList<>(list1.size() + list2.size());
    list.addAll(list1);
    list.addAll(list2);// ww  w  . j a v a2s. co m
    return list;
}

From source file:Main.java

public static <T, C extends Collection<T>> List<T> merge(Collection<C> splits) {
    if (splits == null || splits.isEmpty()) {
        return Collections.emptyList();
    }/*from  w  ww  .  j a  v  a  2 s .c  o  m*/
    List<T> list = new ArrayList<>();
    for (Collection<T> split : splits) {
        list.addAll(split);
    }
    return list;
}

From source file:com.google.mr4c.util.PathUtils.java

/**
  * Takes the elements of one path and prepends any elements that are missing in another path
*///  ww w .jav  a  2  s  .  c o  m
public static String prependMissingPathElements(String path, String otherPath, String separator) {

    List<String> pathElements = Arrays.asList(StringUtils.split(path, separator));
    List<String> otherElements = Arrays.asList(StringUtils.split(otherPath, separator));
    List<String> toAdd = new ArrayList<String>();
    for (String element : otherElements) {
        if (!pathElements.contains(element)) {
            toAdd.add(element);
        }
    }
    List<String> newElements = new ArrayList<String>();
    newElements.addAll(toAdd);
    newElements.addAll(pathElements);
    return StringUtils.join(newElements, separator);
}

From source file:Main.java

public static <E> List<E> join(List<E> list1, List<E> list2) {
    List<E> joinedList = newList();
    if (list1 != null) {
        joinedList.addAll(list1);
    }/*from w w  w .j  a v a 2 s.co m*/
    if (list2 != null) {
        joinedList.addAll(list2);
    }
    return joinedList;
}

From source file:minij.TestFiles.java

public static List<Object[]> getFiles() {
    List<Object[]> files = new LinkedList<>();
    files.addAll(getFiles(null, EXAMPLE_PROGRAM_PATH_WORKING));
    files.addAll(getFiles(ParserException.class, EXAMPLE_PROGRAM_PATH_PARSE_FAILING));
    files.addAll(getFiles(SemanticAnalyserException.class, EXAMPLE_PROGRAM_PATH_TYPE_FAILING));
    files.addAll(getFiles(RunOutputException.class, EXAMPLE_PROGRAM_PATH_RUNTIME_FAILING));
    return files;
}

From source file:Main.java

/**
 * Returns a new list containing the second list appended to the first list.
 *///from w  ww.  java  2 s  .c  o  m
public static <T> List<T> mergeLists(List<T> list1, List<T> list2) {
    List<T> merged = new LinkedList<T>();
    if (list1 != null) {
        merged.addAll(list1);
    }
    if (list2 != null) {
        merged.addAll(list2);
    }
    return merged;
}

From source file:Main.java

@SafeVarargs
public static <A> List<A> listCat(List<A>... lists) {
    if (lists.length == 0)
        return Collections.<A>emptyList();
    else if (lists.length == 1)
        return lists[0];
    else {//from  w w w  .  ja v a2 s . com
        List<A> full = new ArrayList<A>();
        for (List<A> xs : lists)
            full.addAll(xs);
        return full;
    }
}

From source file:Main.java

/**
 * Convert the list of lists into a single list
 *///from w  w  w.j ava2  s.  c om
public static <T> List<T> concatenate(List<List<T>> lists) {
    List<T> result = new ArrayList<T>();
    for (List<T> list : lists) {
        result.addAll(list);
    }
    return result;
}