Here you can find the source of removeAll(T[] array, Collection
Parameter | Description |
---|---|
T | The element type |
array | The array |
toRemove | The elements to remove |
public static <T> Map<T, Integer> removeAll(T[] array, Collection<T> toRemove)
//package com.java2s; //License from project: Creative Commons License import java.util.Collection; import java.util.HashMap; import java.util.Map; public class Main { /**/*from w w w . j a v a2s .c o m*/ * Remove the specified elements from the array in-place, replacing them with {@code null}. * <p> * {@link Collection#contains(Object)} is used to determine if an element should be removed. * * @param <T> The element type * @param array The array * @param toRemove The elements to remove * @return A map of the removed elements and their indices */ public static <T> Map<T, Integer> removeAll(T[] array, Collection<T> toRemove) { Map<T, Integer> removed = new HashMap<>(); for (int i = 0; i < array.length; i++) { T element = array[i]; if (toRemove.contains(element)) { array[i] = null; removed.put(element, i); } } return removed; } }