public static < E extends Comparable < E > > E searchMax ( List < E > list ) { if ( list . size ( ) == 0 ) { throw new IllegalArgumentException ( "The list you provided does not have any elements" ) ; } E max = list . get ( 0 ) ; for ( int i = 1 ; i < list . size ( ) ; i ++ ) { if ( list . get ( i ) . compareTo ( max ) > 0 ) { max = list . get ( i ) ; } } return max ; }
Search for the maximum element in the list .