Here you can find the source of contains(List listOfArrays, A[] array)
array
by the definition of Arrays.equal(..) (both arrays must have the same number of elements, and every pair of elements must be equal according to Object.equals).
Parameter | Description |
---|---|
A | the type of the array. |
listOfArrays | the list of arrays to search. |
array | the array to match. |
true
if an equal to array
was found in listOfArrays
, otherwise false
.
public static <A> boolean contains(List<A[]> listOfArrays, A[] array)
//package com.java2s; /*-//from www . j a v a2s.co m * Copyright (C) 2006-2008 Erik Larsson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ import java.util.Arrays; import java.util.List; public class Main { /** * Checks if the given <code>array</code> contains the specified * <code>element</code> at least once. * * @param array the array to search. * @param element the element to look for. * @return true if <code>element</code> was present in <code>array</code>, * and false otherwise. */ public static boolean contains(byte[] array, byte element) { for (byte b : array) { if (b == element) return true; } return false; } /** * Checks if the given <code>array</code> contains the specified * <code>element</code> at least once. * * @param array the array to search. * @param element the element to look for. * @return true if <code>element</code> was present in <code>array</code>, * and false otherwise. */ public static boolean contains(char[] array, char element) { for (char c : array) { if (c == element) return true; } return false; } /** * Checks if the given <code>array</code> contains the specified * <code>element</code> at least once. * * @param array the array to search. * @param element the element to look for. * @return true if <code>element</code> was present in <code>array</code>, * and false otherwise. */ public static boolean contains(short[] array, short element) { for (short s : array) { if (s == element) return true; } return false; } /** * Checks if the given <code>array</code> contains the specified * <code>element</code> at least once. * * @param array the array to search. * @param element the element to look for. * @return true if <code>element</code> was present in <code>array</code>, * and false otherwise. */ public static boolean contains(int[] array, int element) { for (int i : array) { if (i == element) return true; } return false; } /** * Checks if the given <code>array</code> contains the specified * <code>element</code> at least once. * * @param array the array to search. * @param element the element to look for. * @return true if <code>element</code> was present in <code>array</code>, * and false otherwise. */ public static boolean contains(long[] array, long element) { for (long l : array) { if (l == element) return true; } return false; } /** * Checks if the given <code>array</code> contains the specified * <code>element</code> at least once. * * @param array the array to search. * @param element the element to look for. * @return true if <code>element</code> was present in <code>array</code>, * and false otherwise. */ public static <A> boolean contains(A[] array, A element) { for (A a : array) { if (a == element) return true; } return false; } /** * Checks if the given list of arrays contains an array that is equal to * <code>array</code> by the definition of Arrays.equal(..) (both arrays * must have the same number of elements, and every pair of elements must be * equal according to Object.equals). * * @param <A> the type of the array. * @param listOfArrays the list of arrays to search. * @param array the array to match. * @return <code>true</code> if an equal to <code>array</code> was found in * <code>listOfArrays</code>, otherwise <code>false</code>. */ public static <A> boolean contains(List<A[]> listOfArrays, A[] array) { for (A[] curArray : listOfArrays) { if (Arrays.equals(curArray, array)) return true; } return false; } }