按字母顺序按值排序HashMap [英] Order HashMap alphabetically by value
问题描述
我有一个 HashMap< Object,Student>
其中对象是学生的ID,学生是学生的对象。
如何使用学生姓名 student-> getName()
?
相反,你可以使用 如果您想按值排序,您需要将它们复制到排序列表。 I have a How can I resort the HashMap by the Students name, HashMaps are intrinsically unordered and cannot be sorted. Instead, you can use a SortedMap implementation, such as a TreeMap. If you want to sort by the values, you'll need to copy them to a sorted list. 这篇关于按字母顺序按值排序HashMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
但是,即使排序的地图只能按其键排序。
HashMap<Object, Student>
where the Object is the ID of the Student, and the Student is an object from Student.student->getName()
?
However, even a sorted map can only sort by its keys.