return value index in an array - Android java.lang

Android examples for java.lang:array filter

Description

return value index in an array

Demo Code

// Licensed under the Apache License, Version 2.0 (the "License");
//package com.java2s;

public class Main {
    public static int indexOf(int[] list, int item) {
        for (int i = 0; i < list.length; i++) {
            if (list[i] == item) {
                return i;
            }/*from  ww w.j  a  v a 2 s  .c  o m*/
        }
        return -1;
    }

    public static int indexOf(Object[] list, Object item) {
        if (item == null) {
            return -1;
        }
        for (int i = 0; i < list.length; i++) {
            if (list[i].equals(item)) {
                return i;
            }
        }
        return -1;
    }
}

Related Tutorials