Here you can find the source of compare(Collection
public static <T extends Comparable<T>> int compare(Collection<T> a, Collection<T> b)
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { public static <T extends Comparable<T>> int compare(Collection<T> a, Collection<T> b) { int d = a.size() - b.size(); if (d != 0) { return d; }/*from ww w.ja va2 s . com*/ Iterator<T> ai = a.iterator(); Iterator<T> bi = b.iterator(); while (ai.hasNext()) { d = ai.next().compareTo(bi.next()); if (d != 0) { return d; } } return 0; } }