What is Comparable and Comparator interface?

What is Comparable interface?

• This interface can be used for defining natural sorting order of the objects.
• It is present in java.lang package
• It contains a method public int compareTo(Object obj1)

What is Comparator interface?


• This interface can be used for implementing customized sorting order.
• It is present in java.util package
• It contains two methods
public int compare(Object ,Object)
public boolean equals(Object)

What are differences between Comparable and Comparator?
Comparable
Comparator
1This can be used for natural sorting order1This can be used for implementing customized sorting
2This interface present in java.lang package2     This is present in java.util package
3Contains only one method:
public int compareTo(Object obj1)
3     It contains two methods.
public int compare(Object ,Object)
public Boolean equals(Object)

3 comments:

  1. The mind is a great philosopher. And life is not a philosophy, life is a reality. And philosophy is an escape from reality; philosophy means thinking. Life is, there is no question of thought. You can simply jump into it. You can simply experience it. Visit my site for more information.Thank you.

    n8fan.net

    www.n8fan.net

    ReplyDelete
  2. Wow. Awesome article. Please do more articles like this in the future. Very informational and knowledgeable. I will expect more from you in the future. For now i will just bookmark your page and surely I'm gonna come back later to read more. Thank you to the writer!


    Rica
    www.imarksweb.org

    ReplyDelete
  3. I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very
    useful and knowledgeable. I would like to thank you for the effort you have made in writing this article.


    edupdf.org

    ReplyDelete