This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
While implementing Comparable you need to modify the class whose instances you want to sort. In Comparator, you will be creating an whole new class, making it reusable.
Comparator gives you the ability to sort objects is different ways and UNLIKE comparable you can use it sort instances of any other class(including the classes you dont have access to). Hence its extensible.
Looking at the code, you should be able to figure out the remaining differences between them.
Try to make comparable and comparator work with TreeSet one at a time.
SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]
Joined: Feb 09, 2009
Thanks a lot Himalay !!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com