Comparable and Comparator difference between the two interfaces

When we want to sort the collection, if the elements of the collection is the basic data types, that okay, you can directly call the sort method in the Collections utility class just fine.

But if the type is our custom, we would have to go to achieve compareTo method of the Comparable interface.

 

 

 

 

 

 

Published 98 original articles · won praise 43 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_42352666/article/details/104758671