Monday, 28 July 2014

What is different between Comparator and Comparable interfaces?

Comparator:
1. we can use the comparator to difine cutomized sorting order.
2. This interface present in java.util package..
3. This interface having two methods.
         compare()
         equals()
4. No predefined class implements the Comparator interface
                                                                                                    
Comparable:
        
1. we can use comparable to define default natural sorting order.
2. This interface present in java.lang package.
3. It defines only one mthod that is 
        CompareTo()
4. All wrapper classes and String class implements Comparable interface.                         

No comments:

Post a Comment