1. To achieve Comparable interface (replication comparaTo Method)
Mainly to do their own comparison
2. implement a comparator
Mainly to do third-party comparison
3.
我自己做项目遇到的是 **同一类的对象** 进行比较
所以我选择的是**实现comparable接口**:
Sample Code (unsorted)
results
, we can see yet not sorted result of traversing the arraylist age is disordered
4. Now we want to achieve comparable interface to enable an orderly output
The first step
in the need to compare object's class to achieve comparable interfaces I fill up a generic
The second step in this class comparaTo replication method
call the sort method in the third step in the main () method
because I have a collection so I use the sort collections calls ()
The results of
age also ordered the