Here you can find the source of indexOfInstance(List> list, Object object)
Parameter | Description |
---|---|
list | List to search. |
object | Object instance to locate. |
public static int indexOfInstance(List<?> list, Object object)
//package com.java2s; /**/*from ww w . j a v a 2 s . 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 { /** * 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; } }