Java Collection Subtract subtract(Collection c1, Collection c2)

Here you can find the source of subtract(Collection c1, Collection c2)

Description

c1 - c2, does not change input collections, returns new collection (list)

License

Open Source License

Declaration

public static <T> List<T> subtract(Collection<T> c1, Collection<T> c2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.Collection;
import java.util.Collections;

import java.util.List;

public class Main {
    /**/*w  w  w. j a  va 2 s .  com*/
     * c1 - c2, does not change input collections, returns new collection (list)
     */
    public static <T> List<T> subtract(Collection<T> c1, Collection<T> c2) {
        if (c1 == null) {
            return Collections.emptyList();
        }
        List<T> tmp = new ArrayList<>(c1);
        if (c2 != null) {
            tmp.removeAll(c2);
        }
        return tmp;
    }

    public static <T> List<T> emptyList() {
        return Collections.emptyList();
    }
}

Related

  1. subMap(Map map, Collection keys)
  2. substractBackground( final Map> concentrationToSampleReadings, final Map> concentrationToBackgroundReadings)
  3. subtract(Collection a, Collection b)
  4. subtract(Collection c1, Collection c2)
  5. subtract(Collection a, Collection b)
  6. subtract(Collection l1, Collection l2)
  7. subtract(Collection l1, Collection l2)
  8. subtract(final Collection a, final Collection b)
  9. subtract(final Collection a, final Collection b)