Here you can find the source of removeAll(List
Parameter | Description |
---|---|
toRemoveFrom | collection to remove elements from |
elementsToRemove | elements to remove |
public static <T> List<T> removeAll(List<T> toRemoveFrom, Collection<T> elementsToRemove)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**//w w w . j a va 2s . c om * Convenient method to remove elements from a collection. * @param toRemoveFrom collection to remove elements from * @param elementsToRemove elements to remove * @return new collection without the removed elements */ public static <T> List<T> removeAll(List<T> toRemoveFrom, Collection<T> elementsToRemove) { ArrayList<T> subtract = new ArrayList<>(toRemoveFrom); subtract.removeAll(elementsToRemove); return subtract; } /** * Convenient method to remove elements from a collection. * @param toRemoveFrom collection to remove elements from * @param elementsToRemove elements to remove * @return new collection without the removed elements */ public static <T> Set<T> removeAll(Set<T> toRemoveFrom, Collection<T> elementsToRemove) { Set<T> subtract = new HashSet<>(toRemoveFrom); subtract.removeAll(elementsToRemove); return subtract; } }