Java Collection Remove removeOutStrings(Collection values, String newString)

Here you can find the source of removeOutStrings(Collection values, String newString)

Description

Remove um string da colecao caso seja igual ao parametro 'newString'

License

Apache License

Parameter

Parameter Description
values a parameter

Declaration

public static void removeOutStrings(Collection<String> values, String newString) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class Main {
    /** //w ww.  j a  v a 2s  .co m
     * Remove um string da colecao caso seja igual ao parametro 'newString'
     * 
     * @param values
     */
    public static void removeOutStrings(Collection<String> values, String newString) {
        for (Iterator<String> iterator = values.iterator(); iterator.hasNext();) {
            String tmp = (String) iterator.next();

            if (tmp.equals(newString)) {
                iterator.remove();
            }
        }

        //      System.out.println("Lista: " + vehicles.size());
    }

    /**
     * Remove um string da tabela de espalhamento caso seja igual ao parametro 'newString'
     * 
     * @param vehiclesMap
     */
    public static void removeOutStrings(Map<String, List<String>> map, String newString) {
        for (Iterator<Entry<String, List<String>>> iterator = map.entrySet().iterator(); iterator.hasNext();) {
            Map.Entry<String, List<String>> entry = (Map.Entry<String, List<String>>) iterator.next();
            String key = entry.getKey();
            //         List<String> value = entry.getValue();

            if (key.equals(newString)) {
                iterator.remove();
            }
        }

        //      System.out.println("Lista: " + vehicles.size());
    }
}

Related

  1. removeDuplicates(Collection elements)
  2. removeElement(Collection coll)
  3. removeElement(final int index, final Collection coll)
  4. removeElementsOfList(Collection set, Collection elementsToRemove)
  5. removeIfNotPresent(Collection collection, Collection permitted)
  6. removeRightSet(Collection left, Collection right)
  7. removeSafe(Collection collection, V value)