Java Iterable removeIgnoreCase(Iterable haystack, String needle)

Here you can find the source of removeIgnoreCase(Iterable haystack, String needle)

Description

Remove the first occurrence of needle (ignoring case)

License

Open Source License

Parameter

Parameter Description
haystack The iterable list or set to search in
needle The value to search for

Return

True if an element was removed otherwise false

Declaration

public final static boolean removeIgnoreCase(Iterable<String> haystack, String needle) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Iterator;

public class Main {
    /**// ww w  . ja v  a  2s  .  c  om
     * Remove the first occurrence of <code>needle</code> (ignoring case)
     * 
     * @param haystack
     *            The iterable list or set to search in
     * @param needle
     *            The value to search for
     * @return True if an element was removed otherwise false
     */
    public final static boolean removeIgnoreCase(Iterable<String> haystack, String needle) {
        Iterator<String> iterator = haystack.iterator();

        while (iterator.hasNext()) {
            String string = iterator.next();
            if (needle.equalsIgnoreCase(string)) {
                iterator.remove();
                return true;
            }
        }
        return false;
    }
}

Related

  1. iterable(final Iterable in)
  2. max(Iterable iterable)
  3. mergeConsecutiveTokens(Iterable tokens)
  4. prettyPrintComma(Iterable a)
  5. removeElement(final Iterable iterable, int index)
  6. secondOf(final Iterable iterable)
  7. sequenceEqual(Iterable one, Iterable two)
  8. shallowCopy(Iterable ori)
  9. toFriendlyString(Iterable iterable, String seperator)