Java List Remove removeIgnoreCase(String needle, List haystack)

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

Description

remove Ignore Case

License

Open Source License

Parameter

Parameter Description
needle A String to find with findIgnoreCase().
haystack A list of String objects to search.

Return

The list with the first matching element removed, if it was found with findIgnoreCase().

Declaration

public static List<String> removeIgnoreCase(String needle,
        List<String> haystack) 

Method Source Code

//package com.java2s;
/* ***** BEGIN LICENSE BLOCK *****
 *
 * This file is part of Weave.//from w w  w .  j  a v  a  2 s. c  o m
 *
 * The Initial Developer of Weave is the Institute for Visualization
 * and Perception Research at the University of Massachusetts Lowell.
 * Portions created by the Initial Developer are Copyright (C) 2008-2015
 * the Initial Developer. All Rights Reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 * 
 * ***** END LICENSE BLOCK ***** */

import java.util.Arrays;

import java.util.List;

public class Main {
    /**
     * @param needle A String to find with findIgnoreCase().
     * @param haystack A list of String objects to search.
     * @return The list with the first matching element removed, if it was found with findIgnoreCase().
     */
    public static List<String> removeIgnoreCase(String needle,
            List<String> haystack) {
        int index = findIgnoreCase(needle, haystack);
        if (index >= 0)
            haystack.remove(index);
        return haystack;
    }

    public static int findIgnoreCase(String needle, String[] haystack) {
        return findIgnoreCase(needle, Arrays.asList(haystack));
    }

    /**
     * @param needle A String to find with String.equalsIgnoreCase().
     * @param haystack A list of String objects to search.
     * @return The index of the first matching String, or -1 if it did not match anything in the List.
     */
    public static int findIgnoreCase(String needle, List<String> haystack) {
        if (needle == null)
            return haystack.indexOf(null);

        for (int index = 0; index < haystack.size(); index++)
            if (needle.equalsIgnoreCase(haystack.get(index)))
                return index;
        return -1;
    }
}

Related

  1. removeFrom(List list, T member)
  2. removeFromArray(String[] fieldList, String exludeElement)
  3. removeFromListByClass(final List list, final String className)
  4. removeFromListMap(T key, U value, Map> map)
  5. removeIgnoreCase(List l, String s)
  6. removeItems(List list, T... remove)
  7. removeList(List l)
  8. removeMember(String[] list, String id)
  9. removeObject(List l, T o)