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 <T> List<T> union(final Collection<T> a, final Collection<T> b) {
    List<T> result = new ArrayList<T>(a);
    result.addAll(b);
    return result;
}

From source file:Main.java

public static <T> List<T> unicon(List<T> list1, List<T> list2) {
    List<T> list = new ArrayList();
    list.addAll(list1);
    list.addAll(list2);/*  w  ww.ja  v a  2  s.co m*/
    return list;
}

From source file:Main.java

public static <T> List<T> merge(final List<T> a, final List<T> b) {
    final List<T> retVal = new ArrayList<T>();
    retVal.addAll(a);
    retVal.addAll(b);//from   w  ww . j  a v  a2  s.  c  o m
    return retVal;
}

From source file:Main.java

public static <E extends Object> List<E> union(List<E> list1, List<E> list2) {
    List<E> toReturn = new ArrayList<E>();
    toReturn.addAll(list1);
    toReturn.addAll(list2);/*from www.  j a v a  2  s  .c  o m*/
    return toReturn;
}

From source file:Main.java

/**
 * Transformation operation for a {@link Collection} to a {@link List}.
 * //from  ww w  . jav a 2 s. c  om
 * @param <E>
 *            the type of the given and returned values
 * @param collection
 *            the collection to transform
 * @return the new {@link List}, containing all entries of the given
 *         collection
 */
public static <E extends Object> List<E> asList(Collection<E> collection) {
    List<E> list = new LinkedList<E>();
    list.addAll(collection);
    return list;
}

From source file:Main.java

public static double computeFrequencyWeightedDice(Collection<String> c1, Collection<String> c2) {
    List<String> union = new ArrayList<>();
    union.addAll(c1);
    union.addAll(c2);// w  ww  .  jav a 2s .  co  m

    List<String> intersection = new ArrayList<>(union);
    intersection.retainAll(c1);
    intersection.retainAll(c2);

    if (intersection.size() == 0)
        return 0.0;
    double score = 2 * (double) intersection.size() / (c1.size() + c2.size());
    return score;

}

From source file:Main.java

public static <T> boolean isSubset(List<T> subList, List<T> list) {
    if (subList == null || list == null || subList.isEmpty() || list.isEmpty()) {
        return false;
    }/*from  w ww  . j a v a  2s . c  o  m*/
    List<T> subList1 = new ArrayList();
    subList1.addAll(subList);

    for (T t : list) {
        if (subList1.contains(t)) {
            subList1.remove(t);
        }
    }
    if (subList1.isEmpty()) {
        return true;
    }
    return false;
}

From source file:Main.java

public static <T> List<T> union(List<T> a, List<T> b) {
    List<T> result = new ArrayList<>();
    List<T> alls = new ArrayList<>(a);
    alls.addAll(b);
    for (T t : alls) {
        boolean has = false;
        for (T r : result) {
            if (r.equals(t)) {
                has = true;//from  ww w  .ja  v a 2  s. c o  m
                break;
            }
        }
        if (!has) {
            result.add(t);
        }
    }
    return result;
}

From source file:Main.java

public static <T> void rotate(Collection<T> collection, int rotateStep) {
    List<T> list = new LinkedList<T>();
    list.addAll(collection);
    collection.clear();/*from w w  w. j av a  2  s  .  c  o m*/
    if (rotateStep > 0) {
        if (rotateStep > list.size())
            rotateStep %= list.size();
        collection.addAll(list.subList(list.size() - rotateStep, list.size()));
        collection.addAll(list.subList(0, list.size() - rotateStep));
    } else {
        if (Math.abs(rotateStep) > list.size())
            rotateStep %= list.size();
        rotateStep = Math.abs(rotateStep);
        collection.addAll(list.subList(rotateStep, list.size()));
        collection.addAll(list.subList(0, rotateStep));
    }
}

From source file:Main.java

public static <T extends Object> List<T> addAll(final List<T> firstList, final List<T> secondList) {
    final List<T> result = new ArrayList<>(firstList);
    result.addAll(secondList);
    return result;
}