Here you can find the source of getIndexObject(Object[] data, Object object)
Parameter | Description |
---|---|
data | The array to search in |
object | The element to search for |
Parameter | Description |
---|---|
NullPointerException | If the object to search for is null |
NoSuchElementException | If the specified object cannot be found |
public static int getIndexObject(Object[] data, Object object)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Arrays; import java.util.NoSuchElementException; public class Main { /**/*from w ww .j a va 2 s. c om*/ * Find the index of an element in an array. Elements are compared using the * object.equals(otherObject) method. * * @param data The array to search in * @param object The element to search for * @returns The index of that element * @throws NullPointerException If the object to search for is null * @throws NoSuchElementException If the specified object cannot be found */ public static int getIndexObject(Object[] data, Object object) { int x = new ArrayList<>(Arrays.asList(data)).indexOf(object); if (x == -1) { throw new NoSuchElementException("StringUtils : index lookup in array failed for object " + object + ". Data length is " + data.length); } return x; } }