You always been in confusion to differentiate the differences between these two things. Actually speaking Comparable and Comparator are both the Interfaces in Java. Both are since Jdk version 1.2 means quite old still enough to confuse us so far. Basically, the purpose of these two interfaces is to compare two objects. Now you might wondering why we need another class or interface just to compare objects when we already have equals() method in Object class? So, let me give you some background so you better understand the purpose of existence of these interfaces and eventually we will also see the benefits of each one over another plus when to use which interface. Okay! The Background... I hope you might aware about collection framework in java. Collections are objects in java which does the job of container for objects and which theoretically holds unlimited objects. now typed collections holds only the objects which having same type of which collection is. List, Se
Read and understand java programming language and its core concepts. Blog is carefully written and crafted to explain language concepts with easy way, so you can chase java!