Java tutorial
//package com.java2s; import com.google.common.primitives.Ints; import javax.annotation.Nonnull; import java.util.*; public class Main { public static <T extends Comparable<? super T>> int compareAsList(@Nonnull Collection<? extends T> list1, @Nonnull Collection<? extends T> list2) { int res = Ints.compare(list1.size(), list2.size()); if (res != 0) return res; Iterator<? extends T> elements2 = list2.iterator(); for (T element1 : list1) { res = element1.compareTo(elements2.next()); if (res != 0) return res; } return 0; } public static <T> int compareAsList(@Nonnull Comparator<? super T> elementComparator, @Nonnull Collection<? extends T> list1, @Nonnull Collection<? extends T> list2) { int res = Ints.compare(list1.size(), list2.size()); if (res != 0) return res; Iterator<? extends T> elements2 = list2.iterator(); for (T element1 : list1) { res = elementComparator.compare(element1, elements2.next()); if (res != 0) return res; } return 0; } }