Platinum Partner

Java Comparator Interface

// A quick example of how to sort two objects using Java's Comparator interface.
// The call to Collections.sort uses an anonymous inner function to define
// the comparison between two objects.


    public String[] sortNodes(ArrayList nodes) {
        Node[] sortedNodes = new Node[nodes.size()];
        Collections.sort(nodes, new Comparator() {
            public int compare(Node o1, Node o2) {
                return o2.priority - o1.priority;
            }
        });
        for (int i=0; i < nodes.size(); i++) {
            sortedNodes [i] = nodes.get(i);
        }
        return sortedNodes ;
    }
    
class Node{
    public String name = null;
    public int priority;
}
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}