Difference between Compareble and Comparator interface
What is difference between Comparable and Comparator interface 1) Comparable interface is in java.lang package Comparator interface is in java.util package ================================ 2) int compareTo(Object o1) method takes input as only object int compare(Object o1, Objecto2) method takes input as 2 object ================================ 3) java.lang.Comparable: int compareTo(Object inuptObject1) This method compares this object with inputObject1. Returned int value has the following meanings. 1. positive (this) object is greater than inuptObject1 2. zero (this) object equals to inuptObject1 3. negative (this) object is less than inuptObject1 java.util.Comparator: int compare(Object object1, Object object2) This method compares object1 and object2 objects. Returned int value has the following meanings. 1. positive object1 is greater than object2 2. zero ...
Comments
Post a Comment