Android examples for java.util:Map
Remove key in collection from Map
/*//from w w w. j a va 2 s . c o m ******************************************************************************* * Copyright (C) 1996-2015, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ import java.util.Collection; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import java.util.regex.Matcher; public class Main{ /** * Utility that ought to be on Map * @param m * @param itemsToRemove * @param <K> * @param <V> * @return map passed in */ public static <K, V> Map<K, V> removeAll(Map<K, V> m, Collection<K> itemsToRemove) { for (Iterator it = itemsToRemove.iterator(); it.hasNext();) { Object item = it.next(); m.remove(item); } return m; } /** * Remove matching items * @param <T> * @param <U> * @param c * @param f * @return */ public static <T, U extends Collection<T>> U removeAll(U c, ObjectMatcher<T> f) { for (Iterator<T> it = c.iterator(); it.hasNext();) { T item = it.next(); if (f.matches(item)) it.remove(); } return c; } public static String remove(String source, UnicodeSet removals) { StringBuffer result = new StringBuffer(); int cp; for (int i = 0; i < source.length(); i += UTF16.getCharCount(cp)) { cp = UTF16.charAt(source, i); if (!removals.contains(cp)) UTF16.append(result, cp); } return result.toString(); } }