Here you can find the source of isSorted(List
Parameter | Description |
---|---|
list | List |
public static <T> boolean isSorted(List<T> list)
//package com.java2s; /*//from w w w . j av a2 s . c om // This software is subject to the terms of the Eclipse Public License v1.0 // Agreement, available at the following URL: // http://www.eclipse.org/legal/epl-v10.html. // You must accept the terms of that agreement to use this software. // // Copyright (C) 2001-2005 Julian Hyde // Copyright (C) 2005-2012 Pentaho and others // All Rights Reserved. */ import java.util.*; public class Main { /** * Returns whether a list is strictly sorted. * * @param list List * @return whether list is sorted */ public static <T> boolean isSorted(List<T> list) { T prev = null; for (T t : list) { if (prev != null && ((Comparable<T>) prev).compareTo(t) >= 0) { return false; } prev = t; } return true; } }