Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsReverseOrderExample4 { public static void main(String[] args) { //Create linked list object LinkedList
list = new LinkedList
(); //Add values in the list list.add(50); list.add(-20); list.add(120); list.add(-80); //Sort the list and Create comparator for reverse order Comparator
cmp = Collections.reverseOrder(null); Collections.sort(list, cmp); //Print the list System.out.println("List sorted in ReverseOrder: "); for(int i : list) { System.out.println(i+ " "); } } }
Output