Java Array Has inArray(String needle, String... haystack)

Here you can find the source of inArray(String needle, String... haystack)

Description

Test, if a string occur in an array

License

Open Source License

Parameter

Parameter Description
needle the string that should be find in the haystack
haystack the set of strings we want to know if the needle is in there

Declaration

public static boolean inArray(String needle, String... haystack) 

Method Source Code

//package com.java2s;
/*//  w w  w .j a v  a  2 s  .  c o m
 * 
 * Copyright 2012 lexergen.
 * This file is part of lexergen.
 * 
 * lexergen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * lexergen 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with lexergen.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * lexergen:
 * A tool to chunk source code into tokens for further processing in a compiler chain.
 * 
 * Projectgroup: bi, bii
 * 
 * Authors: Johannes Dahlke
 * 
 * Module:  Softwareprojekt ?bersetzerbau 2012 
 * 
 * Created: Apr. 2012 
 * Version: 1.0
 *
 */

public class Main {
    /**
     * Test, if a string occur in an array
     * @param needle the string that should be find in the haystack
     * @param haystack the set of strings we want to know if the needle is in there
     * @return
     */
    public static boolean inArray(String needle, String... haystack) {
        for (String string : haystack) {
            if (string.equals(needle))
                return true;
        }
        return false;
    }
}

Related

  1. inArray(final T[] array, final U search)
  2. inArray(int[] arr, int search)
  3. inArray(int[] array, int needle)
  4. inArray(Object[] ps, Object p)
  5. inArray(String arg, String[] array)
  6. inArray(String str, String[] stringArray)
  7. inArray(String string, String[] strings)
  8. inArray(String value, String[] s)
  9. inArray(String value, String[] values)