Getting elments from specific postion

Returning 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.

Returning the starting position of the last occurrence of the specified target list within the specified source list, or -1 if there is no such occurrence.

package collection.demos;



import java.util.ArrayList;

import java.util.Collections;

import java.util.List;



public class GettingIndexOfSubList {



    public static void main(String[] args) {

        ArrayList<String> names = new ArrayList<String>();

        names.add("Naveen");

        names.add("Neha");

        names.add("Deepak");

        names.add("Anchal");

        names.add("Nawaz");

        names.add("Avanish");

        names.add("Jai Ram");

        names.add("Kanchan");



        List<String> names1 = names.subList(24);

        System.out.println("Sublist : " + names1);

        int index = Collections.indexOfSubList(names, names1);

        System.out.println("Index Of list names1      : " + index);

        index = Collections.lastIndexOfSubList(names, names1);

        System.out.println("Last Index Of list names1 : " + index);

    }

}

No comments:

Popular Posts