[关闭]
@duyao 2015-05-20T02:26:38.000000Z 字数 505 阅读 1002

hashmap和arraylist遍历

codeTool


  1. TeamService tService=new TeamService();
  2. //hashmap用entry遍历
  3. HashMap<Integer, ArrayList<Student> > hasmap=tService.getAllTeam();
  4. Iterator it = hasmap.entrySet().iterator();
  5. while(it.hasNext()){
  6. Entry entry=(Entry)it.next();
  7. //先得到object,再转
  8. Object key=entry.getKey();
  9. int teamid=Integer.parseInt(key.toString());
  10. Object value=entry.getValue();
  11. ArrayList<Student> arrayList=(ArrayList<Student>)value;
  12. //arraylist遍历,知道类型,取出,找到对应的arraylist
  13. for (Student student : arrayList) {
  14. System.out.println(student.getStuid());
  15. }
  16. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注