I have a HashMap<Object, Student>
where the Object is the ID of the Student, and the Student is an object from Student.
How can I resort the HashMap by the Students name, student->getName()
?
HashMaps are intrinsically unordered and cannot be sorted.
Instead, you can use a SortedMap implementation, such as a TreeMap.
However, even a sorted map can only sort by its keys.
If you want to sort by the values, you'll need to copy them to a sorted list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With