Here we list all the differences between Comparable and Comparator Interface In Java.
Know Also : Comparator Interface
Comparable
|
Comparator
|
It belongs to java.lang; package.
|
It belongs to java.util; package.
|
It has method compareTo(Object ob).
|
It has method compare(Object ob1,Object ob2).
|
It provides single sorting sequence, because one
object is provided in the method.
|
It provides multiple sorting sequence, because two
objects are provided in the method.
|
Class whose object is to be sorted must implement
this interface.
|
Class whose object is to be sorted there is no
need to implement this interface. Some other class can implement this
interface.
|
Collections.sort(list);
Here objects are sorted on the basis of
compareTo() method.
|
Collections.sort(list,Comparator);
Here objects are sorted on the basis of compare()
method.
|
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Java I/O Tutorial

No comments:
Post a Comment