Java List Sort isSorted(List> items, boolean asc)

Here you can find the source of isSorted(List> items, boolean asc)

Description

is Sorted

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <T> boolean isSorted(List<Comparable<T>> items, boolean asc) 

Method Source Code


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

Related

  1. interpolateLinearlyQuantile(List sortedDataAscendingOrder, Double p)
  2. isEqualList(final List list1, final List list2, Comparator c, boolean sortList)
  3. isSorted(Iterable list)
  4. isSorted(List list)
  5. isSorted(List list)
  6. isSorted(List list, Comparator c)
  7. isSorted(List list)
  8. isSorted(List list)
  9. isSorted(List list)