Difference between Comparator and comparable in Collections
807591Apr 22 2008 — edited Apr 22 2008i have been going through the collections chapter and i understand that to sort a collection(list or map or set)we need to use the Collections interface which has a compareTo method that takes in the list that we need to sort as its argument and for this we need to make the class in which we create the list to implement comparable interface and implement the compareTo method.
This is as per my understanding my doubt is there is a line in the book im reading(SCJP 5 by kathy serra)that the difference between Comparable and Comparator is that
Comparator interface you can use it to sort instances of any class�even classes you can't modify�
unlike the Comparable interface, which forces you to change the class whose instances you want to sort.
i dint understand this sentence and what do they exactly mean by classes you cant modify...please clarify...thanks in advance.