One.
Next you want to do a sort of student, should make a comparison method. By observing the other part of the program, students have a comparative approach and are ranked by age.
Now the key to sort, (I think who called the key, who called the value is irrelevant, but the position of the decision), the front of the HashMap to change to TreeMap,
Just traverse the keyset, and now you are ready to use EntrySet.
The results were sorted, ordered by age.
If you want to sort by name, you need to get a comparator. There is,
The student is the one that compares the person. This comparator, the set of person, can be used, and the collection of Student,worker can also be used.
It is certain that you can receive both this type and the parent type. The student is saved, and can be received by the student in the parent class.
Do not look at the API of the TreeMap collection, but also know that there is a comparator inside it.
Just a little change, sort by alphabetical order. After learning TreeSet, it is very simple to learn treemap.
Java-preliminary Understanding-Common Object API (Collection framework-map collection-Store custom objects)