Generic method to get index Of an element inside an array - Android java.lang

Android examples for java.lang:array

Description

Generic method to get index Of an element inside an array

Demo Code

import java.lang.reflect.Array;
import java.util.List;

public class Main{

    public static <T> int indexOf(T[] array, T object) {
        for (int i = 0; i < array.length; i++) {
            if (object.equals(array[i])) {
                return i;
            }//from   w w w  .  j a  va2s  .  com
        }
        return -1;
    }

}

Related Tutorials