Understanding Comparable Interface
Let's discuss Comparable Interface in Java.
We'll cover the following...
Comparable introduction
Collections.sort()
method sorts the given List in ascending order. But the question is, how does the sort()
method decide which element is smaller and which one is larger?
Each wrapper class(Integer, Double, or Long), String class, and Date class implements an interface called Comparable. This interface contains a compareTo(T o)
method which is used by sorting methods to sort the ...
Access this course and 1400+ top-rated courses and projects.