Java学习——HashMap

遍历

Map map = new HashMap();
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map; public class testMap {
public static void main(String[] args){
testMap test = new testMap();
HashMap map = new HashMap<String, String>();
map.put("a", "123");
map.put("a", "456");
map.put("b", "789");
test.transMap(map);
}
void transMap(HashMap map){
Iterator iter = map.entrySet().iterator();
while(iter.hasNext()){
Map.Entry entry =(Map.Entry)iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
System.out.println((String)key + ":" + (String)val);
}
}
}

输出

a:456
b:789

dd

上一篇:centos7下安装docker(14安装docker machine)


下一篇:解决Apache CXF 不支持传递java.sql.Timestamp和java.util.HashMap类型问题