Here you can find the source of isSorted(List
Parameter | Description |
---|---|
list | a parameter |
c | a parameter |
public static <E> boolean isSorted(List<E> list, Comparator<? super E> c)
//package com.java2s; //License from project: Open Source License import java.util.Comparator; import java.util.Iterator; import java.util.List; public class Main { /**//from w w w. j av a 2 s . c o m * Checks that the list is sorted * @param list * @param c * @return */ public static <E> boolean isSorted(List<E> list, Comparator<? super E> c) { if (list.isEmpty()) return true; Iterator<E> i = list.iterator(); E lastR = i.next(); while (i.hasNext()) { E r = i.next(); if (c.compare(lastR, r) > 0) return false; } return true; } }