Java Array Contain arrayContains(String[] pArray, String pItem)

Here you can find the source of arrayContains(String[] pArray, String pItem)

Description

Check if an array contains a given value.

License

Open Source License

Parameter

Parameter Description
pArray the array where to look for the value
pItem the value to look for

Return

true if the value has been found in the array

Declaration

public static boolean arrayContains(String[] pArray, String pItem) 

Method Source Code

//package com.java2s;
/*// w w w.  j  a va2  s.  c o m
 *   LibreOffice extension for syntax highlighting
 *   Copyright (C) 2008  C?dric Bosdonnat cedric.bosdonnat.ooo@free.fr
 *
 *   This library is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Library General Public
 *   License as published by the Free Software Foundation;
 *   version 2 of the License.
 *
 *   This library is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *   Library General Public License for more details.
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this library; if not, write to the Free
 *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

public class Main {
    /**
     * Check if an array contains a given value.
     *
     * @param pArray the array where to look for the value
     * @param pItem the value to look for
     *
     * @return <code>true</code> if the value has been found in the array
     */
    public static boolean arrayContains(String[] pArray, String pItem) {
        boolean contained = false;

        int i = 0;
        while (!contained && i < pArray.length) {
            contained = pArray[i].equals(pItem);
            i++;
        }

        return contained;
    }
}

Related

  1. arrayContains(String[] array, String str)
  2. arrayContains(String[] array, String value)
  3. arrayContains(String[] array, String value)
  4. arrayContains(String[] array, String word)
  5. arrayContains(String[] parent, String[] child)
  6. ArrayContains(String[][] arr, String s)
  7. arrayContains(T haystack[], T needle)
  8. arrayContains(T search, T[] array, boolean def)
  9. arrayContains(T[] arr, T item)