Java 8 List.sort usage -
list class in java 8 has new method sort added it. please clarify when should prefer use opposed collections.sort(..) method?
there no functional difference because collections.sort(list) calls list.sort(null) , collections.sort(list, comparator) calls list.sort(comparator).
so it's matter of style - when providing own comparator, calling sort on list more natural , readable using external static method.
however if want sort list in natural order, collections.sort(list) maybe clearer list.sort(null).
Comments
Post a Comment