Here you can find the source of equalsToElement(final Object[] arr, final Object obj)
Parameter | Description |
---|---|
arr | the array |
obj | the element to compare |
public static boolean equalsToElement(final Object[] arr, final Object obj)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004-2013//from w w w . j ava 2 s.co m * Contributors: L. Armanet, M. Camerlenghi, L. Cardonne, S. Delageniere, * L. Duparchy, S. Ohlsson, P. Pascal, I. Schneider, S.Schulze, * F. Torres * * This file is part of the MIS tools package. * * The MIS tools package 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 3 of the License, or * (at your option) any later version. * * The MIS tools package 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 the MIS tools package. If not, see <http://www.gnu.org/licenses/>. ******************************************************************************/ import java.util.List; public class Main { /** * Checks if at least one array element equals the passed parameter. * * @param arr * the array * @param obj * the element to compare * @return true, if at least one array element equals to the passed parameter, otherwise false */ public static boolean equalsToElement(final Object[] arr, final Object obj) { if (arr == null) { if (obj == null) { return true; } return false; } if (obj == null) { return false; } for (int i = 0; i < arr.length; i++) { if (arr[i] instanceof String && obj instanceof String) { if (((String) arr[i]).equalsIgnoreCase((String) obj)) { return true; } } else if (arr[i].equals(obj)) { return true; } } return false; } /** * Checks if at least one array element equals the passed parameter. * * @param arr * the array * @param obj * the element to compare * @return true, if at least one array element equals to the passed parameter, otherwise false */ public static <T> boolean equalsToElement(final List<T> arr, final T obj) { if (arr == null) { if (obj == null) { return true; } return false; } if (obj == null) { return false; } for (int i = 0; i < arr.size(); i++) { if (arr.get(i) instanceof String && obj instanceof String) { if (((String) arr.get(i)).equalsIgnoreCase((String) obj)) { return true; } } else if (arr.get(i).equals(obj)) { return true; } } return false; } }