Here you can find the source of isSorted(Iterable
From http://stackoverflow.com/questions/3047051/how-to-determine-if-a-list-is-sorted-in-java
Parameter | Description |
---|---|
iterable | a parameter |
T | a parameter |
public static <T extends Comparable<? super T>> boolean isSorted(Iterable<T> iterable)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**/*from www . j a va2 s .c om*/ * From http://stackoverflow.com/questions/3047051/how-to-determine-if-a-list-is-sorted-in-java * @param iterable * @param <T> * @return */ public static <T extends Comparable<? super T>> boolean isSorted(Iterable<T> iterable) { Iterator<T> iter = iterable.iterator(); if (!iter.hasNext()) { return true; } T t = iter.next(); while (iter.hasNext()) { T t2 = iter.next(); if (t.compareTo(t2) > 0) { return false; } t = t2; } return true; } }