Java List Sort isSorted(List list)

Here you can find the source of isSorted(List list)

Description

checks wether or not the list given is sorted

License

Open Source License

Parameter

Parameter Description
list a parameter
T a parameter

Declaration

public static <T extends Comparable<T>> boolean isSorted(List<T> list) 

Method Source Code

//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;
    }
}

Related

  1. isSorted(List list)
  2. isSorted(List> items, boolean asc)
  3. isSorted(List list, Comparator c)
  4. isSorted(List list)
  5. isSorted(List list)
  6. isSortedDescending(List list)
  7. isStringListSortedDesc(List list)
  8. isUnsortedEventsMatch(List actual, List expected)
  9. ListToSortedArray(List list)