What is comparable and comparator interface? List their differences
Answer / Sudhir Singh Chahar
"The Comparable and Comparator interfaces in Java are used for comparing objects. They help define a total ordering between instances of a class.n
1. Comparable Interface: A class implements the Comparable interface to compare its own instances. It defines the compareTo(Object o) method that compares the current object with another object passed as an argument. Each class can implement only one Comparable interface.
2. Comparator Interface: The Comparator interface is used for comparing two objects of any classes. It also defines a compare(T obj1, T obj2) method. Multiple Comparators can be created for a single class and they can be used to define different comparison rules."
| Is This Answer Correct ? | 0 Yes | 0 No |
C and C++ has constructors and distructors, why does Java does not have distructors?
How do you replace a string in java?
What is a string what operation can be performed out with the help of a string?
What is general methodology?
Can we call virtual funciton in a constructor ?
What is role of void keyword in declaring functions?
What is immutable data?
What is immutable in java?
Can a final variable be initialized in constructor?
What is arrays sort in java?
List out five keywords related to exception handling ?
who can we create the object of a class? in how many ways we can create it (max 5)