Iterate both keys and values from a map in Java
Description
The following code shows how to iterate both keys and values from a map.
Example
//from www .j a v a 2 s . com
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class Main {
public static void main(String[] argv) throws Exception {
Map map = new HashMap();
for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
Object key = entry.getKey();
Object value = entry.getValue();
}
}
}