Here you can find the source of containsInstance(List> list, Object object)
Parameter | Description |
---|---|
list | List to search. |
object | Object instance to locate. |
public static boolean containsInstance(List<?> list, Object object)
//package com.java2s; /**//from w ww . jav a 2s . c o m * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. * If a copy of the MPL was not distributed with this file, You can obtain one at * http://mozilla.org/MPL/2.0/. * * This Source Code Form is also subject to the terms of the Health-Related Additional * Disclaimer of Warranty and Limitation of Liability available at * http://www.carewebframework.org/licensing/disclaimer. */ import java.util.List; public class Main { /** * Returns true if the list contains the exact instance of the specified object. * * @param list List to search. * @param object Object instance to locate. * @return True if the object was found. */ public static boolean containsInstance(List<?> list, Object object) { return indexOfInstance(list, object) > -1; } /** * Performs a lookup for the exact instance of an object in the list and returns its index, or * -1 if not found. This is different from the usual implementation of a list search the uses * the object's equals implementation. * * @param list List to search. * @param object Object instance to locate. * @return Index of the object. */ public static int indexOfInstance(List<?> list, Object object) { for (int i = 0; i < list.size(); i++) { if (list.get(i) == object) { return i; } } return -1; } }