Comparator Interface

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • praveenkumarvpk
    New Member
    • Oct 2007
    • 22

    Comparator Interface

    Difference between compare() & equals() with an example....
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by praveenkumarvpk
    Difference between compare() & equals() with an example....
    If you implement "first one", then it will be OK.
    For details see API doc.

    Debasis Jana.

    Comment

    • praveenkumarvpk
      New Member
      • Oct 2007
      • 22

      #3
      Originally posted by dmjpro
      If you implement "first one", then it will be OK.
      For details see API doc.

      Debasis Jana.
      I wnt d diffrence bet 'em....

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by praveenkumarvpk
        I wnt d diffrence bet 'em....
        The equals() method just checks whether two objects are equal or not. The compare()
        method defines an 'order' of elements e1 < e2 < e3 ... en. If e1,compare(e2)
        is less than zero then e1 < e2; if it returns greater than zero then e2.compare(e1)
        returns less than zero so e2 < e1. Otherwise both are considered equal and then
        e1.equals(e2) == e2.equals(e1) == true.

        The compare() method imposes a 'stronger' relation between two objects than
        the equals() method does.

        kind regards,

        Jos

        Comment

        Working...