Search Interview Questions
| More than 3000 questions in repository.|
There are more than 900 unanswered questions.
Click here and help us by providing the answer.
Have a video suggestion.
Click Correct / Improve and please let us know.
|Java - Interview Questions and Answers|
|Ans. "equals" is the method of object class which is supposed to be overridden to check object equality. x.equals(y) means the references x and y are holding objects that are equal. |
The compareTo() method is used for comparing two objects in Java. It is usually defined for the classes whose objects needs to be ordered through Comparable interface or need to be part of an ordered collection like TreeSet or TreeMap.
|Help us improve. Please let us know the company, where you were asked this question :|
|Like Discuss Correct / Improve  equals  compareTo  equals vs compareTo|
|Can we override compareTo method for Enumerations ?|
|How TreeMap orders the elements if the Key is a String ?|
|If we add Enum constants to a sorted collection ( Treemap , TreeSet ), What will be the order in which they will be maintained ?|
|If compareTo() method returns zero, does it mean that the objects are always equal?|
|What is the use of defining equals , compareTo and hashcode methods in a class ? Where are they used ?|