Java List Last Item lastIndexOfIdentical(List l, T element, int startingAt)

Here you can find the source of lastIndexOfIdentical(List l, T element, int startingAt)

Description

Finds the last location of an element in the List using the == operator for comparison.

License

Apache License

Parameter

Parameter Description
element the element to search for. The comparison is performed using <b>==</b> with each element.
l the list to search
startingAt the starting element in the list to search back from

Return

the index of element in the List. Returns -1 if the element is not present.

Declaration


public static <T> int lastIndexOfIdentical(List<T> l, T element, int startingAt) 

Method Source Code

//package com.java2s;
/*//from  w  w w.  j a  v  a2 s.c  o m
Copyright 1996-2010 Ariba, Inc.
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    
$Id: //ariba/platform/util/core/ariba/util/core/ListUtil.java#38 $
*/

import java.util.Collection;

import java.util.List;

public class Main {
    /**
    Finds the last location of an element in the List using the
    <b>==</b> operator for comparison.
        
    @param element the element to search for. The comparison is
    performed using <b>==</b> with each element.
    @param l the list to search
    @param startingAt the starting element in the list to search
    back from
    @return the index of <b>element</b> in the List.  Returns
    <b>-1</b> if the element is not present.
    @aribaapi public
    */

    public static <T> int lastIndexOfIdentical(List<T> l, T element, int startingAt) {
        for (int i = startingAt; i >= 0; i--) {
            if (l.get(i) == element) {
                return i;
            }
        }
        return -1;
    }

    /**
    Finds the last location of an element in the List using the
    <b>==</b> operator for comparison.
        
    @param element the element to search for. The comparison is
    performed using <b>==</b> with each element.
    @param l the list to search
        
    @return the index of <b>element</b> in the List.  Returns
    <b>-1</b> if the element is not present.
    @aribaapi public
    */
    public static <T> int lastIndexOfIdentical(List<T> l, T element) {
        return lastIndexOfIdentical(l, element, l.size() - 1);
    }

    public static int size(Collection list) {
        return list != null ? list.size() : 0;
    }
}

Related

  1. isLast(T object, List list)
  2. isLastIdx(List l, int idx)
  3. isLastIndex(List list, int index)
  4. isLastIndex(List suggestedList, int i)
  5. lastIndexOf(List lines, String... conditions)
  6. listToWorkspaceLocationHistoryString(List lastUsedWorkspaceLocationList)
  7. removeBySwapLast(List a, Object o)
  8. removeLast(List list)
  9. removeLast(List aList)