java hashmap key iteration

前端 未结 7 683
谎友^
谎友^ 2020-12-29 06:46

Is there any way to iterate through a java Hashmap and print out all the values for every key that is a part of the Hashmap?

7条回答
  •  悲&欢浪女
    2020-12-29 07:08

    public class abcd {
        public static void main(String[] args)
        {
           Map testMap = new HashMap();
            testMap.put(10, "a");
            testMap.put(20, "b");
            testMap.put(30, "c");
            testMap.put(40, "d");
            for (Entry entry : testMap.entrySet()) {
                Integer key=entry.getKey();
                String value=entry.getValue();
            }
        }
    }
    

提交回复
热议问题