Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Matthew Lee
6,715 PointsTrouble understanding the Comparator Interface and the compare method and compareTo method.
Hi,
I am working on the java data structures Karaoke project.
I am having trouble understanding the difference between the comparable interface and comparator interface.
Also, the difference between compare and compareTo methods. And why we pass in a Comparator as an argument when calling a sort method.
Thanks
2 Answers
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsI am having trouble understanding the difference between the comparable interface and comparator interface.
Very good answer here
http://stackoverflow.com/questions/4108604/java-comparable-vs-comparator
Please read carefully. And one nice link with a example from there
http://www.digizol.com/2008/07/java-sorting-comparator-vs-comparable.html
Matthew Lee
6,715 PointsThanks! The bottom link helped a lot especially.