Iterating HashMap with string key

This question already has an answer here:

  • Iterate through a HashMap [duplicate] 7 answers

  • Here is the solution. "trying to find the most frequent word that comes up" part is not clear to me

    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
    for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
        System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
    }
    

    “没有理解”试图找出最常出现的词“。你可以试试这个。

    Map<String, Integer> map = new HashMap<String, Integer>();
        map.put("k1", 2);
        map.put("k3", 3);
        map.put("k2", 4);
        Set keySet = map.keySet();
        Iterator it = keySet.iterator();
        while (it.hasNext()) {
            String key = (String) it.next();
            System.out.println(map.get(key));
        }
    
    链接地址: http://www.djcxy.com/p/17996.html

    上一篇: 从树形图对象中提取键

    下一篇: 用字符串键迭代HashMap