Here you can find the source of arrayContains(String[] pArray, String pItem)
Parameter | Description |
---|---|
pArray | the array where to look for the value |
pItem | the value to look for |
true
if the value has been found in the array
public static boolean arrayContains(String[] pArray, String pItem)
//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; } }