public static int indexOfIntArray(int[] array, int key) {
int returnvalue = -1;
for (int i = 0; i < array.length; ++i) {
if (key == array[i]) {
returnvalue = i;
break;
}
}
return returnvalue;
}
Lists.indexOf(array, x -> item == x); // compare in the way you want
这是您的分机号码
public final class Lists {
private Lists() {
}
public static <T> int indexOf(T[] array, Predicate<T> predicate) {
for (int i = 0; i < array.length; i++) {
if (predicate.test(array[i])) return i;
}
return -1;
}
public static <T> int indexOf(List<T> list, Predicate<T> predicate) {
for (int i = 0; i < list.size(); i++) {
if (predicate.test(list.get(i))) return i;
}
return -1;
}
public interface Predicate<T> {
boolean test(T t);
}
}