Shekhar Ray

Greenhorn
+ Follow
since Sep 18, 2016
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Shekhar Ray

Comparable interface is used when sorting order can be added inside the same class and the objects can be sorted according to natural order of fields.

Comparable interface is used when sorting information isn’t available inside the object itself or a custom sorting logic needs to be implemented.

Although you don't need to, but a class can implement both Comparable and Comparator interface. In such scenario, the Comparator takes precedence over Comparable.

Reference:
TopJavaTutorial
7 years ago