Generic method to Search index Of an item in an array - Android java.lang

Android examples for java.lang:Array Element

Description

Generic method to Search index Of an item in an array

Demo Code


//package com.java2s;

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  www .j a  v  a  2  s  . c  o m*/
        }
        return -1;
    }
}

Related Tutorials