java.util.Collections.lastIndexOfSubList() 方法
描述
lastIndexOfSubList(List<?>, List<?>) 方法用于获取指定目标列表在指定源列表中最后一次出现的起始位置。
声明
以下是 java.util.Collections.lastIndexOfSubList() 方法的声明。
public static int lastIndexOfSubList(List<?> source, List<?> target)
参数
source − 这是要在其中搜索最后一次出现的目标的列表。
target − 这是作为源子列表搜索的列表。
返回值
方法调用返回指定目标列表在指定源列表中最后一次出现的起始位置,如果没有这样的出现,则返回-1。
异常
NA
示例
下面的例子展示了 java.util.Collections.lastIndexOfSubList() 的用法。
package com.tutorialspoint;
import java.util.*;
public class CollectionsDemo {
public static void main(String args[]) {
// create two array list objects
List arrlistsrc = new ArrayList();
List arrlisttarget = new ArrayList();
// populate two lists
arrlistsrc.add("A");
arrlistsrc.add("B");
arrlistsrc.add("C");
arrlistsrc.add("D");
arrlistsrc.add("E");
arrlisttarget.add("C");
arrlisttarget.add("D");
arrlisttarget.add("E");
// check starting position of the last occurrenc
int index = Collections.lastIndexOfSubList(arrlistsrc, arrlisttarget);
System.out.println("Starting position is: "+index);
}
}
让我们编译并运行上面的程序,这将产生以下结果.
Starting position is: 2

