public static <T>int detectLastIndex(List<T> list,Predicate<? super T> predicate){
  if (list instanceof RandomAccess) {
    return RandomAccessListIterate.detectLastIndex(list,predicate);
  }
  int size=list.size();
  int i=size - 1;
  ListIterator<T> reverseIterator=list.listIterator(size);
  while (reverseIterator.hasPrevious()) {
    if (predicate.accept(reverseIterator.previous())) {
      return i;
    }
    i--;
  }
  return -1;
}

public static < T > int detectLastIndex ( List < T > list , Predicate < ? super T > predicate ) { if ( list instanceof RandomAccess ) { return RandomAccessListIterate . detectLastIndex ( list , predicate ) ; } int size = list . size ( ) ; int i = size - 1 ; ListIterator < T > reverseIterator = list . listIterator ( size ) ; while ( reverseIterator . hasPrevious ( ) ) { if ( predicate . accept ( reverseIterator . previous ( ) ) ) { return i ; } i -- ; } return - 1 ; }
returns the last index where the predicate evaluates to true . returns - 1 for no matches .
