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 .