Java Collections Java Java API
java.util.Collections
public static int indexOfSubList(List<?> source, List<?> target)
Returns the starting position of the first occurrence of the specified target list within the specified source list, or -1 if there is no such occurrence.
package com.logicbig.example.collections;import java.util.Arrays;import java.util.Collections;import java.util.List;public class IndexOfSubListExample { public static void main(String... args) { List<Integer> list = Arrays.asList(30, 40); List<Integer> list2 = Arrays.asList(10, 20, 30, 40, 50); int i = Collections.indexOfSubList(list2, list); System.out.println(i); }}
2