Java Array Contain arrayContainsIgnoreCase(String[] array, String str)

Here you can find the source of arrayContainsIgnoreCase(String[] array, String str)

Description

Returns true if and only if the String array contains the given string, case insensitive.

License

Open Source License

Parameter

Parameter Description
array The String array to search with
str The String to search for

Return

true if the String array contains the given String, case insensitive; false otherwise.

Declaration

public static boolean arrayContainsIgnoreCase(String[] array, String str) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*ww w.j a  va2 s . c om*/
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Returns true if and only if the String array contains the given string, case insensitive.
     * @param array The String array to search with
     * @param str The String to search for
     * @return true if the String array contains the given String, case insensitive; false otherwise.
     */
    public static boolean arrayContainsIgnoreCase(String[] array, String str) {
        if (array.length == 0) {
            return false;
        }
        for (int i = 0; i < array.length; i++) {
            if (array[i].equalsIgnoreCase(str))
                return true;
        }

        return false;

    }

    /**
     * Tests whether two string are equal with ignoring the case. The difference to
     * String.equalsIgnoreCase is that in case s1 or s2 is null then this method returns 
     * false.
     * 
     * @param s1 first string to compare
     * @param s2 second string to comapre
     * @return true in case they are equal with ignore case
     */
    public static boolean equalsIgnoreCase(String s1, String s2) {

        if (s1 == null || s2 == null) {
            return false;
        }

        return s1.equalsIgnoreCase(s2);
    }
}

Related

  1. arrayContains(T[] ts, T t)
  2. arrayContains1(String[] parent, String[] child)
  3. arrayContainsElement(T[] array, T element)
  4. arrayContainsEntry(T[] array, T entry)
  5. arrayContainsIgnoreCase(String[] array, String searchKey)
  6. arrayContainsInt(int[] array, int test)
  7. arrayContainsLower(String[] lemmas, String string)
  8. arrayContainsNumber(Number[] array, Number number)
  9. arrayContainsOK(final byte[] b)