How to use Comparator and Comparable in Java? With example

http://javarevisited.blogspot.com/2011/06/comparator-and-comparable-in-java.html If you want to sort collection of object how will you do ? you need to use either comparable for natural sorting or Comparator for more flexible Sorting based on any attribute or combination of attribute in Java. both Comparable and Comparator has method to implement compareTo() and compare(). This Java Comparable tutorial shows how to use Comparable and comparator in Java, how to compare String in Java and how to sort object in Java.

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