Java中怎么遍历map中value值
1个回答
展开全部
public static void main(String[] args){
Map<String, String> map = new HashMap<String, String>();
map.put("id1", "wang");
map.put("id2", "sheng");
//方法一
Set<String> set = map.keySet();
for (String s:set) {
System.out.println(s+","+map.get(s));
}
//方法二
Set<Map.Entry<String, String>> entryseSet=map.entrySet();
for (Map.Entry<String, String> entry:entryseSet) {
System.out.println(entry.getKey()+","+entry.getValue());
}
}
Map<String, String> map = new HashMap<String, String>();
map.put("id1", "wang");
map.put("id2", "sheng");
//方法一
Set<String> set = map.keySet();
for (String s:set) {
System.out.println(s+","+map.get(s));
}
//方法二
Set<Map.Entry<String, String>> entryseSet=map.entrySet();
for (Map.Entry<String, String> entry:entryseSet) {
System.out.println(entry.getKey()+","+entry.getValue());
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询