Here you can find the source of inArray(T needle, T[] hayshack)
Parameter | Description |
---|---|
T | a parameter |
needle | Object to look for |
hayshack | The array to look from |
public static <T> boolean inArray(T needle, T[] hayshack)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . j ava2 s . c om * Tell whether an object is in an array * @param <T> * @param needle Object to look for * @param hayshack The array to look from * @return True if found, false otherwise. */ public static <T> boolean inArray(T needle, T[] hayshack) { for (int i = 0; i < hayshack.length; ++i) { if (needle.equals(hayshack[i])) { return true; } } return false; } /** * Tell whether an int is in an array of ints * @param needle int to find * @param hayshack int list to find from * @return true if the int is in the list, false otherwise */ public static boolean inArray(int needle, int[] hayshack) { for (int i = 0; i < hayshack.length; ++i) { if (needle == hayshack[i]) { return true; } } return false; } }