Here you can find the source of isSorted(List
Parameter | Description |
---|---|
list | a parameter |
T | a parameter |
public static <T extends Comparable<T>> boolean isSorted(List<T> list)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { /**/*from w w w. j av a 2 s. co m*/ * checks wether or not the list given is sorted * * @param list * @param <T> * @return */ public static <T extends Comparable<T>> boolean isSorted(List<T> list) { for (int i = 1; i < list.size(); ++i) { if (list.get(i - 1).compareTo(list.get(i)) > 0) { return false; } } return true; } }