Java Collection Remove removeSafe(Collection collection, V value)

Here you can find the source of removeSafe(Collection collection, V value)

Description

Type-safe wrapper for Collection#remove(Object) method.

License

Open Source License

Declaration

public static <V> boolean removeSafe(Collection<V> collection, V value) 

Method Source Code

//package com.java2s;
// under the terms of the Eclipse Public License v1.0 which accompanies

import java.util.Collection;
import java.util.Map;

public class Main {
    /**/*from   w ww . j  a  va  2 s. c  om*/
     * Type-safe wrapper for {@link Map#remove(Object)} method. It restricts
     * type of key and makes sure that you do not try to remove key of wrong
     * type.
     */
    public static <K, V> V removeSafe(Map<K, V> map, K key) {
        return map.remove(key);
    }

    /**
     * Type-safe wrapper for {@link Collection#remove(Object)} method. It restricts
     * type of a value and makes sure that you do not call method for the value
     * wrong type.
     */
    public static <V> boolean removeSafe(Collection<V> collection, V value) {
        return collection.remove(value);
    }
}

Related

  1. removeElement(final int index, final Collection coll)
  2. removeElementsOfList(Collection set, Collection elementsToRemove)
  3. removeIfNotPresent(Collection collection, Collection permitted)
  4. removeOutStrings(Collection values, String newString)
  5. removeRightSet(Collection left, Collection right)