DESKTOP-2IHO1NT_20200909秦文亮
问题
public class ListTest6 {
public static void main(String[] args) {
List<Integer> source = List.of( 100 , 20 , 99 , 78 , 9527 , 1 , 0 , -8526 );
System.out.println( source );
System.out.println( "- - - - - - - - - - - - - - - - - - - - - - -" );
List<Integer> list = new ArrayList<>();
list.addAll( source );
System.out.println( list );
Comparator<Integer> comparator = new Comparator<Integer>() {
@Override
public int compare(Integer a , Integer b ) {
if( a != null || b != null ) {
//return a - b ;
return b - a ;
}
return 0;
}
};
list.sort( comparator ); // Java 8 : default void sort( Comparator<? super E> c )
System.out.println( list );
}
}
比较器是怎么比较的?
吐槽
今天又是难过的一天。
点赞