What is Comparable interface?
• This interface can be used for defining natural sorting order of the objects.
• It is present in java.lang package
• It contains a method public int compareTo(Object obj1)
What is Comparator interface?
• This interface can be used for implementing customized sorting order.
• It is present in java.util package
• It contains two methods
public int compare(Object ,Object)
public boolean equals(Object)
What are differences between Comparable and Comparator?
• This interface can be used for defining natural sorting order of the objects.
• It is present in java.lang package
• It contains a method public int compareTo(Object obj1)
What is Comparator interface?
• This interface can be used for implementing customized sorting order.
• It is present in java.util package
• It contains two methods
public int compare(Object ,Object)
public boolean equals(Object)
What are differences between Comparable and Comparator?
Comparable
|
Comparator
|
1This can be used for natural sorting order | 1This can be used for implementing customized sorting |
2This interface present in java.lang package | 2 This is present in java.util package |
3Contains only one method: public int compareTo(Object obj1) | 3 It contains two methods. public int compare(Object ,Object) public Boolean equals(Object) |
No comments:
Post a Comment