回答

收藏

遍历 HashMap

技术问答 技术问答 362 人阅读 | 0 人回复 | 2023-09-11

迭代 a 项目的最佳方法是HashMap什么?
- R9 p" h- i" o                                                                2 K4 }/ F3 v5 {1 G; Y
    解决方案:                                                                ) l& Q7 M9 h5 C" Y' v
                                                                entrySet()像这样迭代:
2 h& \* o& e) H- }7 Z( Ppublic static void printMap(Map mp) {    Iterator it = mp.entrySet().iterator();     while (it.hasNext()) {        Map.Entry pair = (Map.Entry)it.next();         System.out.println(pair.getKey()   " = "   pair.getValue();;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;it.remove(); // avoids a ConcurrentModificationException
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则