Comparable vs. Comparator interface?
I'm still having trouble understanding the difference with these two interface types.
When do we use comparable, and when do we use comparator? What can comparator do which comparable can't?
I understand that compareTo() compares a implicit parameter with a explicit parameter, where compare() compares two explicit parameters, but what does this difference mean?
Re: Comparable vs. Comparator interface?
Comparable is an interface generally implemented by a class that is Comparable.
In other words, a class which you want to assign a "natural order" to.
You use a Comparator to provide ordering for something that does not have a natural order, or whose order for a particular List (for example) is not the same as its natural order.