Here you can find the source of isSorted(List
@SuppressWarnings("unchecked") public static <T> boolean isSorted(List<Comparable<T>> items, boolean asc)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { @SuppressWarnings("unchecked") public static <T> boolean isSorted(List<Comparable<T>> items, boolean asc) { for (int n = 0; n < items.size() - 1; n++) { Comparable<T> current = items.get(n); Comparable<T> next = items.get(n + 1); int cmp = current.compareTo((T) next); if (asc && cmp > 0) { return false; } else if (!asc && cmp < 0) { return false; }//from w w w .jav a2s. co m } return true; } }