The Coffee Machine

Java & Eclipse tips blog

  • Categories

  • Archives

  •  

    September 2008
    M T W T F S S
    « Aug    
    1234567
    891011121314
    15161718192021
    22232425262728
    2930  

Archive for September 11th, 2008

Sort a list of elements with the Comparable interface

Posted by ObLiB on September 11, 2008

JavaSometimes 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.

Read the rest of this entry »

Posted in Java | Tagged: , , , , , , , | Leave a Comment »