Collections.lastIndexOfSubList(List <?> source, List <?> target) has the following syntax.
public static int lastIndexOfSubList(List <?> source, List <?> target)
In the following code shows how to use Collections.lastIndexOfSubList(List <?> source, List <?> target) method.
//from w w w . jav a 2 s .co m import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { public static void main(String args[]) { // create two array list objects List<String> arrlistsrc = new ArrayList<String>(); List<String> arrlisttarget = new ArrayList<String>(); // populate two lists arrlistsrc.add("A"); arrlistsrc.add("from java2s.com"); arrlistsrc.add("C"); arrlistsrc.add("D"); arrlistsrc.add("E"); arrlisttarget.add("C"); arrlisttarget.add("D"); arrlisttarget.add("E"); // check starting position of the last occurrence int index = Collections.lastIndexOfSubList(arrlistsrc, arrlisttarget); System.out.println("Starting position is: "+index); } }
The code above generates the following result.