Wednesday, February 20, 2008

BeanComparator

Sometimes you just have the requirement to sort java collections...In that case the BeanComparator from Jakarta Commons is quite handy:

ArrayList sortFields = new ArrayList();
sortFields.add(new BeanComparator("lastName"));
sortFields.add(new BeanComparator("firstName"));
ComparatorChain multiSort = new ComparatorChain(sortFields);
java.util.Collections.sort(rows,multiSort);

No comments: