Sunday, January 6, 2019

Both are interfaces in Java. Here some common differences between Comparator and Comparable.
  1. Comparator in Java is defined in java.util package while Comparable interface in Java is defined in java.lang package.
  2. Comparator has the method int compare(T o1,T o2) which compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. While Comparable has method public int compareTo(T o) which returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
  3. compare method of Comparator compares its two arguments for order. compareTo method of Comparable interface compares this object with the specified object for order.
  4. Comparator has equals(Object obj) method while Comparable doesn't.

0 comments:

Post a Comment

selenium-repo by venu

Blog helps to a student or IT employee to develop or improve skills in Software Testing.
For Online Classes Email us: gadiparthi122@mail.com

Followers

About Me

My photo
Hyderabad, Andhra Pradesh, India
I am Automation Testing Professional. I have completed my graduation in B.Tech (Computers) from JNTU Hyderabad and started my career in Software Testing accidentally since then, I passionate on learning new technologies

Contact Form

Name

Email *

Message *

Popular Posts