Java Collection Subtract subtract(Collection l1, Collection l2)

Here you can find the source of subtract(Collection l1, Collection l2)

Description

Returns all elements that are in l1 but not in l2 as a list.

License

Open Source License

Declaration

public static <T> List<T> subtract(Collection<T> l1, Collection<T> l2) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2008 Tran Nam Quang.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from  ww  w.j  ava2s  . co m
 *    Tran Nam Quang - initial API and implementation
 *******************************************************************************/

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Main {
    /**
     * Returns all elements that are in <tt>l1</tt> but not in <tt>l2</tt> as
     * a list.
     */
    public static <T> List<T> subtract(Collection<T> l1, Collection<T> l2) {
        List<T> newList = new ArrayList<T>(l1);
        newList.removeAll(l2);
        return newList;
    }
}

Related

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