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 thread life cycle?
What two classes are used to read data only?
0 Answers TryTechnicals Pvt Ltd,
How to add panel to a Frame?
How many functional interfaces does java 8 have?
What is the length of a string?
When can we say that threads are not lightweight process in java?
int a=10,b=20,c=30 a= b+c;b=a+c;c=a+b; System.out.println("The value is"+a+b+c;
How does abstract modifier work?
What is the type of lambda expression?
In a my eclipse editor if i want to switch from jdk 1.4 to jdk 1.6 how to do that???? Initially i have jdk1.4
we cannot create an object of interface but we can create a variable of it
What is a final class ?