0 votes
by (480 points)
Why do we use comparator?

1 Answer

0 votes
by (320 points)
Comparable interface can be used to provide single way of sorting whereas Comparator interface is used to provide different ways of sorting. For using Comparable, Class needs to implement it whereas for using Comparator we don't need to make any change in the class.

Related questions

0 votes
1 answer
asked Nov 28, 2019 by sensor (640 points)
0 votes
1 answer
asked Nov 28, 2019 by rectifier (460 points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 2, 2021 by comparator (480 points)
0 votes
1 answer
0 votes
1 answer
...