java.util.Collections.lastIndexOfSubList() 方法


java.util.Collections.lastIndexOfSubList() 方法

package com.codingdict;

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);    
   }    
}