Java Array Contain arrayContains(String[] array, String value)

Here you can find the source of arrayContains(String[] array, String value)

Description

Returns true if the given array contains the given value.

License

Open Source License

Parameter

Parameter Description
array The array to look into
value The value to look for

Declaration

public static boolean arrayContains(String[] array, String value) 

Method Source Code

//package com.java2s;
/*/*from  w w  w  . j  a  v a2s.c om*/
 *   Copyright 2013 The Portico Project
 *
 *   This file is part of cpptask.
 * 
 *   cpptask is free software; you can redistribute and/or modify it under the
 *   terms of the Common Development and Distribution License (the "License").
 *   You may not use this file except in compliance with the License.
 *
 *   Use of this software is strictly AT YOUR OWN RISK!!!
 *   Obtain a copy of the License at http://opensource.org/licenses/CDDL-1.0
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */

public class Main {
    /**
     * Returns true if the given array contains the given value. False otherwise. Each
     * element will be stripped of whitespace before being compared.
     * 
     * @param array The array to look into
     * @param value The value to look for
     */
    public static boolean arrayContains(String[] array, String value) {
        for (String potential : array) {
            if (potential.trim().equals(value))
                return true;
        }

        // didn't find it
        return false;
    }
}

Related

  1. arrayContains(Object[] element, Object[][] array)
  2. arrayContains(Object[] haystack, Object needle)
  3. arrayContains(String[] arr, String sg, boolean ignoreCase)
  4. arrayContains(String[] array, String str)
  5. arrayContains(String[] array, String value)
  6. arrayContains(String[] array, String word)
  7. arrayContains(String[] parent, String[] child)
  8. arrayContains(String[] pArray, String pItem)
  9. ArrayContains(String[][] arr, String s)