Java Array Has inArray(int[] array, int needle)

Here you can find the source of inArray(int[] array, int needle)

Description

in Array

License

Open Source License

Parameter

Parameter Description
array a parameter
needle a parameter

Return

True if the given needle is in the array.

Declaration

public static final boolean inArray(int[] array, int needle) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2008 Dennis Schenk, Peter Siska.
 * 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:/*from   w w  w  .j  ava 2 s  .  co m*/
 *     Dennis Schenk - initial implementation
 *     Peter Siska    - initial implementation
 *******************************************************************************/

public class Main {
    /**
     * 
     * @param array
     * @param needle
     * @return True if the given needle is in the array.
     */
    public static final boolean inArray(int[] array, int needle) {
        boolean found = false;
        for (int i = 0; i < array.length; i++) {
            if (array[i] == needle) {
                found = true;
                break;
            }
        }
        return found;
    }
}

Related

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