Tuesday, January 17, 2012

Collections Sort with more than one key

Collections Sort with more than one key
        Collections.sort(jobs, new Comparator() {
            public int compare(Job o1, Job o2) {
                int result = o1.getJobNumPrefix().compareTo(o2.getJobNumPrefix());
                if (result == 0) {
                    result = o1.getJobNumSuffix().compareTo(o2.getJobNumSuffix());
                }
                if (result == 0) {
                    result = o1.getDocRev().compareTo(o2.getDocRev());
                }
                return result;
            }
        });

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home