Java的泛型集合类:
HashMap<String,Integer> hm = new HashMap<String,Integer>();
hm.put("zxx",19);
hm.put("lis",18);
Set<Map.Entry<String,Integer>> mes= hm.entrySet();
for(Map.Entry<String,Integer> me : mes) {
System.out.println(me.getKey() + ":" + me.getValue());
}
l 对在jsp页面中也经常要对Set或Map集合进行迭代:
<c:forEach items=“${map}” var=“entry”>
${entry.key}:${entry.value}
</c:forEach>
代码:
Java代码
1.HashMap<String, Integer> maps=new HashMap<String, Integer>();
2. maps.put("a", 1);
3. maps.put("b", 1);
4. maps.put("c", 1);
5.
6. Set<Map.Entry<String, Integer>> entrySet=maps.entrySet();
7. for (Map.Entry<String, Integer> entry : entrySet) {
8. System.out.println(entry.getKey()+":"+entry.getValue());
9. }
|