What is a Comparable Interface?
What is a comparable interface – Coders can also order objects using java comparable interface. And rather than any type of class for that object. As a result, java uses user-defined class for this interface.
You can find java comparable interface inside the java.lang package since it is located inside that package. Therefore it contains only 1 method which seems like to be CompareTo(objects). Furthermore the interface provides single sorting element on a single data member only. So For an example it may be rollno, name, age or anything else.
compareTo(Object obj) method
Therefore to compare the current object with the specified object we used the syntax :
public int compareTo(Object obj)
Hence, Here is a list of what the element we can sort :
The programming language that I specialize in is Java, because I think Java programming language is more universal and of course because I like it regardless of any reason.