我想让我的key和value 对应着显示,即
1
aa
2
bb
3
cc
map.put("1",aa);
map.put("2",bb);
map.put("3",cc);
//怎么循环输出我想要的结果
1
aa
2
bb
3
cc
map.put("1",aa);
map.put("2",bb);
map.put("3",cc);
//怎么循环输出我想要的结果
调试欢乐多
map.put("1", "aa");
map.put("2", "bb");
map.put("3", "cc");
for(Map.Entry entry:map.entrySet()){
System.out.println(entry.getKey());
System.out.println(entry.getValue());
}---jdk1.5+
//jdk1.4 刚才不好意思 我的环境是1.4的 想1.5写起来简单点 就没有测试! Map map = new LinkedHashMap();
map.put("1", "aa");
map.put("2", "bb");
map.put("3", "cc");
Iterator it = map.entrySet().iterator();
Map.Entry entry = null;
while(it.hasNext()){
entry = (Map.Entry)it.next();
System.out.println(entry.getKey());
System.out.println(entry.getValue());
}这个应该满足你的要求了! 如果 你不要求顺序 你可以把LinkedHashMap 改成HashMap