Java ListIterator Usage lastIndexOf(List list, T element)

Here you can find the source of lastIndexOf(List list, T element)

Description

Returns the last index of a specific elemen in a list.

License

Open Source License

Parameter

Parameter Description
list the list
element the element

Return

the last index of element in list

Declaration

public static <T> int lastIndexOf(List<? super T> list, T element) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.List;
import java.util.ListIterator;

public class Main {
    /** Returns the last index of a specific elemen in a list.
     * @param list the list//from   w  w w.jav a2s .c  o  m
     * @param element the element
     * @return the last index of {@code element} in {@code list}*/
    public static <T> int lastIndexOf(List<? super T> list, T element) {
        ListIterator<? super T> iter = list.listIterator();
        int index = -1;

        while (iter.hasNext()) {
            Object t = iter.next();
            if (element.equals(t)) {
                index = iter.previousIndex();
            }
        }

        return index;
    }
}

Related

  1. insertBefore(List list, E... elements)
  2. intern(ListIterator in)
  3. internStringsInList(List list)
  4. isEqual(java.util.List list1, java.util.List list2)
  5. iteratorBinarySearchGet(ListIterator i, int index)
  6. listEquals(List left, List right)
  7. listHasIdentContent(List list_1, List list_2)
  8. listToStringArray(java.util.List list)
  9. makeSortFieldFallbackExpr(List fieldNames)