现在的位置: 首页 > 综合 > 正文

Map遍历

2017年08月09日 ⁄ 综合 ⁄ 共 561字 ⁄ 字号 评论关闭
Map<string,student> map=new Map<string,student>;
Student stu1=new Student(1,longer,male);
Student stu1=new Student(1,longer,male);
map.put("1",stu1);
map.put("2" stu2);

三种方法遍历map
1
Collection<studnet> c=map.values();
for(Iterator lt=c.iterator();it.hasNext();)
{ studnet=it.next();
}
2
set<string> c=map.keySet();
for(Iterator lt=c.iterator();it.hasNext();)
{ 
String id=(String)it.next();
map.get(id);
3
}
set<Map.entry<string,student>> c=map.entrySet();
for(Iterator it=c.iterator;it.hasNext;){
Map.Entry<string,studnet> entry=(Map.Entry<string,student>)it.next();
entry.getKey();
entry.getValue();
}

抱歉!评论已关闭.