Here you can find the source of lastIndexOfIdentical(List
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 |
public static <T> int lastIndexOfIdentical(List<T> l, T element, int startingAt)
//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; } }