Mega Code Archive

 
Categories / Java Tutorial / Collections
 

Sort items of an ArrayList with Collections reverseOrder()

import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; public class Main {   public static void main(String[] args) {     List<String> colours = new ArrayList<String>();     colours.add("red");     colours.add("green");     colours.add("blue");     colours.add("yellow");     colours.add("cyan");     colours.add("white");     colours.add("black");     Collections.sort(colours);     System.out.println(Arrays.toString(colours.toArray()));     Collections.sort(colours, Collections.reverseOrder());     System.out.println(Arrays.toString(colours.toArray()));   } }