Here you can find the source of isSorted(Iterable
public static <T> boolean isSorted(Iterable<T> iterable, final Comparator<T> cmp)
//package com.java2s; //License from project: Open Source License import java.util.Comparator; import java.util.Iterator; public class Main { public static <T> boolean isSorted(Iterable<T> iterable, final Comparator<T> cmp) { Iterator<T> iter = iterable.iterator(); if (!iter.hasNext()) { return true; }//from w ww. ja v a 2 s .com T t = iter.next(); while (iter.hasNext()) { T t2 = iter.next(); if (cmp.compare(t, t2) > 0) return false; t = t2; } return true; } }