Core Java - Interview Questions and Answers for 'Equals vs compareto' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

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.
Label / Company      Label / Company / Text

   



Core Java - Interview Questions and Answers for 'Equals vs compareto' - 1 question(s) found - Order By Newest

 Q1. Difference between equals and compareTo in Java ?Core Java2019-02-05 16:38:11

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


Related Questions

  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 ?



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: