Skip to content

Instantly share code, notes, and snippets.

@rmg007
Created October 16, 2022 13:52
Show Gist options
  • Select an option

  • Save rmg007/fbac9e2ce7ae1fd3b785043ae1967fc9 to your computer and use it in GitHub Desktop.

Select an option

Save rmg007/fbac9e2ce7ae1fd3b785043ae1967fc9 to your computer and use it in GitHub Desktop.
Sort Lis tUsing Comparato rReverse Order
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class SortListUsingComparatorReverseOrder {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>(List.of(3, 6, 8, 2));
list.sort(Comparator.reverseOrder());
System.out.println(list);//output [8, 6, 3, 2]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment