简体   繁体   English

HashMap和排序

[英]HashMap and sorting

I am building a trie, each node has a hashmap with sons' value stored, and keys are their name. 我正在建立一个特里,每个节点都有一个哈希表,其中存储了儿子的值,并且键是它们的名称。

I'm using hashmap because, mainly, I need performances instead of sorting, instead I would have used treemap, of course. 我使用hashmap的原因是,主要是我需要性能而不是排序,所以我当然会使用treemap。

Now, I need, just in a function, to sort hash map values by key values (that are strings). 现在,我只需要在函数中按键值(即字符串)对哈希映射值进行排序。 Now I'm using iterator to iterate values. 现在,我正在使用迭代器来迭代值。

Any suggest? 有什么建议吗?

Thank you 谢谢

您应该将map.keySet放在一个列表中进行排序,并在此排序键列表上进行迭代。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM