ListUtils { public static <T> int firstIndexOf(List<? extends T> list, Predicate<? super T> predicate) { Objects.requireNonNull(list, "list"); Objects.requireNonNull(predicate, "predicate"); for (int i = 0; i < list.size(); i++) { if (predicate.test(list.get(i))) { return i; } } return -1; } private  ListUtils(); static int firstIndexOf(List<? extends T> list, Predicate<? super T> predicate); static boolean addIfNotPresent(List<? super T> list, T element); static boolean addIfNotPresent(List<? super T> list, int index, T element); static Collector<T, ?, ImmutableList<T>> toImmutableList(); static Collector<T, ?, List<T>> joining(Supplier<? extends T> separator); static Collector<T, ?, List<T>> joining(Supplier<? extends T> prefix,
                                                     Supplier<? extends T> separator,
                                                     Supplier<? extends T> suffix); static Replacement<T> replaceIn(List<T> list);  }
@Test public void testFirstIndexOfNulls() { assertAll( () -> assertThrows(NullPointerException.class, () -> ListUtils.firstIndexOf(null, x -> true)), () -> assertThrows(NullPointerException.class, () -> ListUtils.firstIndexOf(new ArrayList<>(), null)) ); }
@Test public void testFirstIndexOf() { List<String> list = new ArrayList<>(); list.add("1"); list.add("12"); list.add("123"); assertAll( () -> assertEquals(-1, ListUtils.firstIndexOf(list, str -> str.startsWith("0"))), () -> assertEquals(0, ListUtils.firstIndexOf(list, str -> str.equals("1"))), () -> assertEquals(1, ListUtils.firstIndexOf(list, str -> str.length() == 2)), () -> assertEquals(2, ListUtils.firstIndexOf(list, str -> str.endsWith("3"))) ); }