intermediateCollections10 of 436
What is the difference between Comparable and Comparator?
Tests whether you know Comparable defines a class's single natural ordering via compareTo() implemented on the class itself, while Comparator defines an external, pluggable ordering you can swap at call time -- and that you need Comparator the moment you want more than one sort order for the same type.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response