Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.Iterator;
import java.util.List;

public class Main {
    /**
     * 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).
     */
    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;
    }
}