Close

Java Collections - Collections.indexOfSubList() Examples

Java Collections Java Java API 


Class:

java.util.Collections

java.lang.Objectjava.lang.Objectjava.util.Collectionsjava.util.CollectionsLogicBig

Method:

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.


Examples


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

Output

2




See Also