As far as I know there is no such function.
It may be worth noting that it could actually take no more time to sort it than to determine whether it is sorted or not.
You could always wrap it in an object that maintains a sorted
flag for you.
You could implement the function yourself quite efficiently using:
/**
* Bridge function to the isSorted(Iterable<Comparable>) below
* allowing arrays to tested too.
*
* @param <T> - The elements in the array.
* @param a - The array.
* @return - true if the Array is sorted - false otherwise.
*/
public static <T extends Comparable<T>> boolean isSorted(T[] a) {
return isSorted(Arrays.asList(a));
}
/**
* Checks sortedness of any Iterable of Comparables.
*
* @param <I> - The type of the Iterable.
* @param <T> - The type of the Comparable.
* @param a - The Iterable<Comparable> to test.
* @return - true if the Iterable is sorted - false otherwise.
*/
public static <T extends Comparable<T>> boolean isSorted(Iterable<T> a) {
// Remember the previous element.
T prev = null;
for (T it : a) {
if (prev != null && it.compareTo(prev) < 0) {
// This should be before prev! Not sorted!!
return false;
}
prev = it;
}
// All in order.
return true;
}