Skip to content


December 6, 2011

Always i commit mistakes and correct those mistakes (probably that is how i am).

Wrote my own Comparator and the sorting logic was becoming very hefty and unreadable.

Long time back, one of my ex-colleague Ganesh had a discussion on this and i believe he wrote some samples as well.

So, implemented my sorting logic based on the BeanComparator.

Some lessons on that.


Comparator<T> firstNameComparator = new BeanComparator(“firstName”, new NullComparator(true));
Collections.sort(employeeList, firstNameComparator );

But why we need NullComparator?

If the values can be null, then the BeanComparator would thrown NullPointerException.


No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: