Java Array Contain arrayContainsOnlyIgnoreCase(String[] array, String... strs)

Here you can find the source of arrayContainsOnlyIgnoreCase(String[] array, String... strs)

Description

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

License

Open Source License

Parameter

Parameter Description
array The String array to search with
strs The Strings to search for

Return

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

Declaration

public static boolean arrayContainsOnlyIgnoreCase(String[] array,
        String... strs) 

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://w ww .j  av  a  2  s. co m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Returns true if and only if the String array contains only the given strings, case insensitive.
     * @param array The String array to search with
     * @param strs The Strings to search for
     * @return true if the String array contains only the given Strings, case insensitive; false otherwise.
     */
    public static boolean arrayContainsOnlyIgnoreCase(String[] array,
            String... strs) {
        if (array.length == 0) {
            return false;
        }

        for (int i = 0; i < array.length; i++) {
            if (arrayContainsIgnoreCase(strs, array[i]))
                continue;
            else
                return false;
        }
        return true;
    }

    /**
     * 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. arrayContainsIgnoreCase(String[] array, String str)
  2. arrayContainsInt(int[] array, int test)
  3. arrayContainsLower(String[] lemmas, String string)
  4. arrayContainsNumber(Number[] array, Number number)
  5. arrayContainsOK(final byte[] b)
  6. arrayContainsOverlap(Object[] array1, Object[] array2)
  7. arrayContainsPartKey(String[] array, String key)
  8. arrayContainsString(String[] arr, String str, boolean isCaseSensitive)
  9. arrayContainString(String[] arrayString, String str)