how to get values from hashmap using loop

This question already has an answer here:

  • How to efficiently iterate over each entry in a 'Map'? 38 answers

  • if (onLine != null) {
        for (String k : onLine.keySet()) {
            for (String v : onLine.get(k)) {
                out.print(v);
            }
        }
    }
    

    java.util.Map为此具有一个values()方法:

    for(List<String> nextArray : onLine.values()) {
        for(String nextString : nextArray) {
            out.print(nextString);
        }
    }
    

    Try this:

    if (onLine != null) {
        for (String key : onLine.keySet()) {
            for (List<String> val : onLine.get(key)) {
                for(String str : val){
                    System.out.print(str);
                }
            }
        }
    }
    

    This will print all the strings in your map.

    链接地址: http://www.djcxy.com/p/23974.html

    上一篇: 无法在JSP中循环映射

    下一篇: 如何使用循环从hashmap中获取值