is Iterable Sorted - Android java.util

Android examples for java.util:Iterable

Description

is Iterable Sorted

Demo Code


import java.util.Comparator;

public class Main {
  private static <T extends Comparable> boolean isSorted(Iterable<T> iterable,
      Comparator<T> comparator) {
    T previous = null;/*  www. j  av  a  2  s.  c om*/
    for (T t : iterable) {
      if (previous != null && comparator.compare(previous, t) < 0)
        return false;
      previous = t;
    }
    return true;
  }
}

Related Tutorials