Basti's Scratchpad on the Internet

Sort Objects Your Way

Note to self, if I ever need to sort objects my way.

import java.util.Comparator;

public class IpComparator implements Comparator {

    public int compare(Object host, Object anotherHost) {

        String hostIp = (String)host.toUpperCase();
        String anotherHostIp = (String)anotherHost.toUpperCase();

        return hostIp.compareTo(anotherHostIp);
    }
}

Collections.sort(arpTable, new IpComparator());
Other posts
comments powered by Disqus