emory-courses / dsa-java

Data Structures and Algorithms in Java
https://emory.gitbook.io/dsa-java/
42 stars 55 forks source link

Comparator v Comparable #74

Closed lcunild closed 4 years ago

lcunild commented 4 years ago

I am confused about the difference between the compare method from the Comparator interface and the compareTo method from the Comparable interface. When should each one be used?

marvinquiet commented 4 years ago

You may want to read this to find the answer. https://www.javatpoint.com/difference-between-comparable-and-comparator