public static <E extends Comparable<E>> boolean isSorted(List<E> list) {
        for(int i = 0; i < list.size() - 1; i++) {           
            if(list.get(i).compareTo(list.get(i + 1)) > 0) {
                return false;
            }
            
        }
        
        return true;
    }
public static < E extends Comparable < E > > boolean isSorted ( List < E > list ) { for ( int i = 0 ; i < list . size ( ) - 1 ; i ++ ) { if ( list . get ( i ) . compareTo ( list . get ( i + 1 ) ) > 0 ) { return false ; } } return true ; }
Check if the list is sorted. It loops through the entire
list once, checking that the elements are sorted.

<br>
<br>

<i>Runtime: </i> O(n)

@param <E> the type of elements in this list.

@param list the list to check
@return <i>true</i> if the list is sorted, else <i>false</i>.