Here you can find the source of removeIgnoreCase(String needle, List
Parameter | Description |
---|---|
needle | A String to find with findIgnoreCase(). |
haystack | A list of String objects to search. |
public static List<String> removeIgnoreCase(String needle, List<String> haystack)
//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; } }