Diff between Comparator and Comparable?
Answers were Sorted based on User's Feedback
Answer / qim2010
The “Comparable” interface allows itself to compare with
another similar object (i.e. A class that implements Comparable
becomes an object to be compared with). The following method
are specified in the interface.
public int compareTo(Object o)
public int compareToIgnoreCase(String str)
The "Comparator" interface is used to compare two different
objects. The following method is specified in the Comparator
interface.
public int compare(Object o1, Object o2)
| Is This Answer Correct ? | 8 Yes | 0 No |
Answer / rajesh
Comparable interface uses Object's compareTo() to compare
the objects. We have to override the compareTo() method in
order to sort.
Where as Comparator, checks for compare() method. You can
sort based on particular property of the object.
| Is This Answer Correct ? | 4 Yes | 2 No |
What is difference between hashset and hashmap?
What is function overriding and overloading in java?
Why we use static and synchronized in method for single thread model example: public static synchronized add(){}
How do you convert string to int in java?
What class of exceptions are generated by the java run-time system?
in a constructor what happen if u call super and this in the same class? i know that it is not possible to call both in the same one? if we call what will happen?
How do you create a method in java?
what is the use of private constructor in core java?
3 Answers OnMobile, Satyam, Yash Technologies,
What are the features of junit?
If two threads call a static method at the same point of time, what will happen?
Can a final variable be manipulated in java?
Can string be considered as a keyword?