Object List Sorting Using BeanComparator

We can sort List<Objects> using BeanComparater instead of writing comparator. The beanutils.jar has to be imported. Default sort order is in ascending order.

For eg.
Collections.sort(postings, new BeanComparator(“resumeCount”));
OR
BeanComparator bc = new BeanComparator(“resumeCount”);
Collections.sort(postings, bc);
Collections.reverse(postings);
Pros:- Concise, Minimal code
Cons:- Low performance, uses reflection (now if a field is renamed, the compiler won’t even report a problem)



Author: InApp
We are a custom software development company offering Testing Services, Application Development, Mobility Solutions & more. Customers: Startups - Fortune 500

Leave a Reply

2 × 1 =