The Coffee Machine

Java & Eclipse tips blog

  • Categories

  • Archives

  • May 2024
    M T W T F S S
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  

Posts Tagged ‘Comparable’

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 »