Dynamic sorting using multiple comparator in java

Saurabh Chopra

In this blog I would like to demonstrate how to sort list of bean class on multiple fields dynamically using java comparator.

Suppose you have a bean class name student with three attribute id, name and address.
You can have a sort order enum with ascending and descending type.

A public method that will return comprator of student type.

For multiple fields comparison you can have a enum for all the fields which is giving compare method for the fields like :
Let execute the above code: 
For Source Code: Source Code

View original post


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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