Sorting an array collections java

// Array sorting 
Integer ARR [] = {3,4,2};
Arrays.sort (ARR); // default ascending
Arrays.sort (arr, Comparator.reverseOrder ()) ; // pass a reverse comparator
Arrays. Stream (ARR) .forEach (the System.out :: Print);

// set sorted
List <Integer> = new new List the ArrayList <> ();
List.add (2); List.add (. 3); List.add ( 1);

list.sort (Comparator.naturalOrder ()); // List natural order
list.stream () forEach (System.out :: println);.
list.sort (Comparator.reverseOrder ()); // List in reverse order
list.stream () forEach (System.out :: println);.

Collections.sort (List); // Sort the Collections of natural
list.stream () forEach (System.out :: println);.
Collections.sort (List, Comparator.reverseOrder ()); // Collections reverse
list.stream () forEach (System.out :: println ).;

Guess you like

Origin www.cnblogs.com/Andrew520/p/11030913.html