Trier une liste en Java

Publié dans Snippet | Marqué avec , ,
Collections.sort(myList, new MyComparator());

public class MyComparator implements Comparator<MyObject> {
    public int compare(MyObject o1, MyObject  o2) {
        if (o1.getInt() == o2.getInt()) {
            return 0;
        if (o1.getInt() < o2.getInt()) {
            return -1;
        return 1;

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>