示例:使用entrySet进行map的遍历,直接通过getKey()和getValue()获取键值
public static void main(String args[]) {
Map<String,String> map = new HashMap<String,String>(16);
map.put("1","张三");
map.put("2","李四");
map.put("3","王五");
Iterator<Map.Entry<String,String>> entryIterator = map.entrySet().iterator();
while (entryIterator.hasNext()) {
Map.Entry<String, String> entry = entryIterator.next();
System.out.println("key="+ entry.getKey() +"value="+ entry.getValue());
}
}