Java List Sub List isSubList(List l1, List l)

Here you can find the source of isSubList(List l1, List l)

Description

Returns true iff l1 is a sublist of l (i.e., every member of l1 is in l, and for every e1 < e2 in l1, there is an e1 < e2 occurrence in l).

License

Open Source License

Declaration

public static <T> boolean isSubList(List<T> l1, List<? super T> l) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {
    /**/*w ww  .ja  va2s. c om*/
     * Returns true iff l1 is a sublist of l (i.e., every member of l1 is in l,
     * and for every e1 &lt; e2 in l1, there is an e1 &lt; e2 occurrence in l).
     */
    public static <T> boolean isSubList(List<T> l1, List<? super T> l) {
        Iterator<? super T> it = l.iterator();
        for (T o1 : l1) {
            if (!it.hasNext()) {
                return false;
            }
            Object o = it.next();
            while ((o == null && !(o1 == null)) || (o != null && !o.equals(o1))) {
                if (!it.hasNext()) {
                    return false;
                }
                o = it.next();
            }
        }
        return true;
    }
}

Related

  1. getSublist(List list, int i)
  2. getSubList(List list, int start, int end)
  3. getSubList(List list, int start, int limit)
  4. getSubListFromStart(List list, int length)
  5. getSubListIndex(Object[] tofind, Object[] tokens)
  6. lastIndexOfSubList(final List list0, final List list1)
  7. slice(List stringList, int subListSize)
  8. split(List from, int subListSize)
  9. splitIntoSubListsByNumber(final List list, final int numberOfSublists)