- June 17, 2014
- Posted by: InApp
- Category: Technology
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.
Collections.sort(postings, new BeanComparator(“resumeCount”));
BeanComparator bc = new BeanComparator(“resumeCount”);
Pros:- Concise, Minimal code
Cons:- Low performance, uses reflection (now if a field is renamed, the compiler won’t even report a problem)