| |
在使用map的时候,想用iterator直接遍历其值,总是不能实现,因为map的entryset()方法不能直接得到值的set,而是一个map.entry的set,那怎么办呢,其实,在entry类也是一个map,他为我们提供了一种取得其数据的方法,看以下代码:
//---------- 处理带图片新闻 -----------// map picmap=(map)request.getattribute("picmap"); system.out.println("picture map size is :"+picmap.size());
iterator piciter=picmap.entryset().iterator();
while(piciter.hasnext()){ system.out.println("abcdefg");
map.entry en=(map.entry)piciter.next(); news n=(news)en.getvalue();
system.out.println(n);
}
这样,我们就可以通过iterator来以此取得map中的数值. 如果我们直接通过iterator piciter=picmap.entryset().iterator();就取得其值的话,那么我们得到的是map.entry的实例,而不是你想要取得的对象
|
|