Here you can find the source of arrayContains(final E[] arr, final E targetValue)
Check if an array contains a value, <a href="http://www.programcreek.com/2014/04/check-if-array-contains-a-value-java/">very efficient</a>
Parameter | Description |
---|---|
arr | The array to check against |
targetValue | The value to check for |
public static <E> boolean arrayContains(final E[] arr, final E targetValue)
//package com.java2s; //License from project: Open Source License public class Main { /**// w ww.ja va 2 s .c om * Check if an array contains a value, <a href="http://www.programcreek.com/2014/04/check-if-array-contains-a-value-java/">very efficient</a> * * @param arr The array to check against * @param targetValue The value to check for * @return {@code true} if the value is found, {@code false} otherwise */ public static <E> boolean arrayContains(final E[] arr, final E targetValue) { for (final E s : arr) { if (s.equals(targetValue)) return true; } return false; } /** * Check if an array contains a value, <a href="http://www.programcreek.com/2014/04/check-if-array-contains-a-value-java/">very efficient</a> * * @param arr The array to check against * @param targetValue The value to check for * @return {@code true} if the value is found, {@code false} otherwise */ static boolean arrayContains(final int[] arr, final int targetValue) { for (final int s : arr) { if (s == targetValue) return true; } return false; } /** * Check if an array contains a value, <a href="http://www.programcreek.com/2014/04/check-if-array-contains-a-value-java/">very efficient</a> * * @param arr The array to check against * @param targetValue The value to check for * @return {@code true} if the value is found, {@code false} otherwise */ public static boolean arrayContains(final byte[] arr, final byte targetValue) { for (final byte s : arr) { if (s == targetValue) return true; } return false; } /** * Check if an array contains a value, <a href="http://www.programcreek.com/2014/04/check-if-array-contains-a-value-java/">very efficient</a> * * @param arr The array to check against * @param targetValue The value to check for * @return {@code true} if the value is found, {@code false} otherwise */ public static boolean arrayContains(final short[] arr, final short targetValue) { for (final short s : arr) { if (s == targetValue) return true; } return false; } /** * Check if an array contains a value, <a href="http://www.programcreek.com/2014/04/check-if-array-contains-a-value-java/">very efficient</a> * * @param arr The array to check against * @param targetValue The value to check for * @return {@code true} if the value is found, {@code false} otherwise */ public static boolean arrayContains(final char[] arr, final char targetValue) { for (final char s : arr) { if (s == targetValue) return true; } return false; } /** * Check if an array contains a value, <a href="http://www.programcreek.com/2014/04/check-if-array-contains-a-value-java/">very efficient</a> * * @param arr The array to check against * @param targetValue The value to check for * @return {@code true} if the value is found, {@code false} otherwise */ public static boolean arrayContains(final long[] arr, final long targetValue) { for (final long s : arr) { if (s == targetValue) return true; } return false; } /** * Check if an array contains a value, <a href="http://www.programcreek.com/2014/04/check-if-array-contains-a-value-java/">very efficient</a> * * @param arr The array to check against * @param targetValue The value to check for * @return {@code true} if the value is found, {@code false} otherwise */ public static boolean arrayContains(final float[] arr, final float targetValue) { for (final float s : arr) { if (s == targetValue) return true; } return false; } /** * Check if an array contains a value, <a href="http://www.programcreek.com/2014/04/check-if-array-contains-a-value-java/">very efficient</a> * * @param arr The array to check against * @param targetValue The value to check for * @return {@code true} if the value is found, {@code false} otherwise */ public static boolean arrayContains(final double[] arr, final double targetValue) { for (final double s : arr) { if (s == targetValue) return true; } return false; } }