According to the new features of JDK, use For to loop Map, such as looping the Key of Map
Java code
for(String dataKey : paraMap.keySet()) { System.out.println(dataKey ); }
What should be noted here is how paraMap is defined. If it is a simple Map paraMap = new HashMap(); then The previous String can only be replaced with Object.
Loop through the key and value of the entire Map, as follows:
Java code
for(Map.Entry<String, Object> entry : paraMap.entrySet()) { System.out.println(entry.getKey()+": "+entry.getValue()); }
In the past, it was looped like this:
java code
Iterator it = paraMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry)it.next(); System.out.println(pairs.getKey() + " = " + pairs.getValue()); }
For more related articles summarizing several looping methods of Java Map, please pay attention to the PHP Chinese website!