Iterator在Map和List中的使用
(2006-10-09 16:59:35)
开发过程中经常用到List和Map,通过调用其他方法得到list后,通过循环形成map,对map中的数据再进行处理时,用Iterator比较方便,如做项目中,业务是一个人对应多个岗位,一个岗位对应多个部门,先通过登陆人的登陆userid,得到对应多个部门的部门name:
//通过userid得到岗位list
List gwlist = getGwList(userid);
Map map = new HashMap();
//形成 岗位map
for(i=0;i
{
String gwid = gwlist.get(i);
map.put("GWID",gwid);
}
Iterator it = map.keySet().iterator();
Map NameMap = new HashMap();
while(it.haxNext())
{
String bmid = it.next().toString();
List bmlist = getBmList(bmid);
for(int i=0;i
{
String name = bmlist.get(i);
NameMap.put("NAME",name);
}
}
分享:
喜欢
0
赠金笔
加载中,请稍候......
评论加载中,请稍候...
发评论
登录名: 密码: 找回密码 注册记住登录状态
昵 称:
评论并转载此博文
发评论
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。