Sometimes you’ve got to sort a list. Instead of doing our own sort method, you can use the Collections.sort(List list) method. To be sorted, your list elements must be “Comparable” (Like int, String, Date etc…). To do this, the only things to do are to implements the Comparable interface and define the public int compareTo(Object object) method in your element class.
Archive for September 11th, 2008
Sort a list of elements with the Comparable interface
Posted by ObLiB on September 11, 2008
Posted in Java | Tagged: ascending, Collections, Comparable, compareTo, descending, List, order, sort | Leave a Comment »


