We would like to know how to reverse a List.
import java.util.*; // w w w . ja v a 2 s. c o m public class MainClass { public static void main(String args[]) { ArrayList simpsons = new ArrayList(); simpsons.add("Bart"); simpsons.add("Hugo"); simpsons.add("Lisa"); simpsons.add("Marge"); simpsons.add("Homer"); simpsons.add("Maggie"); simpsons.add("Roy"); Comparator comp = Collections.reverseOrder(); Collections.sort(simpsons,comp); System.out.println(simpsons); } }
The code above generates the following result.