Java Collection Sort isSort(Collection c)

Here you can find the source of isSort(Collection c)

Description

is Sort

License

Open Source License

Declaration

public static <E extends Comparable<E>> boolean isSort(Collection<E> c) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;
import java.util.Iterator;

public class Main {

    public static <E extends Comparable<E>> boolean isSort(Collection<E> c) {
        E pointer = null, next;//from   w  w  w  .j  a v  a 2  s  .com
        Iterator<E> it = c.iterator();
        if (it.hasNext())
            pointer = it.next();
        while (it.hasNext()) {
            next = it.next();
            if (pointer.compareTo(next) > 0)
                return false;
            pointer = next;
        }
        return true;
    }
}

Related

  1. getSorted(Collection collection)
  2. sort(Collection collection)
  3. sort(Collection collection, Comparator comparator)
  4. sort(Collection items)
  5. sortByDescendingOrder(Map collection)