java中map集合两种遍历方法
2009-08-04 21:29
1311 查看
1.声明一个map: Map map = new HashMap();
2.向map中放值,注意:map是key-value的形式存放的.如:
map.put(”sa”,”dd”);
3.从map中取值:String str = map.get(”sa”).toString();结果是:str = ”dd”;
4.遍历一个map,从中取得key 和value
JDK1.5
Map m = new HashMap();
for (Object o : map.keySet()) {
map.get(o);
}
JDK1.4
Map map = new HashMap() ;
Iterator it = map.entrySet().iterator() ;
while (it.hasNext())
{
Map.Entry entry = (Map.Entry) it.next() ;
Object key = entry.getKey() ;
Object value = entry.getValue() ;
}
2.向map中放值,注意:map是key-value的形式存放的.如:
map.put(”sa”,”dd”);
3.从map中取值:String str = map.get(”sa”).toString();结果是:str = ”dd”;
4.遍历一个map,从中取得key 和value
JDK1.5
Map m = new HashMap();
for (Object o : map.keySet()) {
map.get(o);
}
JDK1.4
Map map = new HashMap() ;
Iterator it = map.entrySet().iterator() ;
while (it.hasNext())
{
Map.Entry entry = (Map.Entry) it.next() ;
Object key = entry.getKey() ;
Object value = entry.getValue() ;
}
相关文章推荐
- java中map集合两种遍历方法
- java中map集合两种遍历方法
- java遍历map集合中的元素的方法。
- Java_遍历Map集合的四种方法
- [Java基础]----遍历Map集合,并获取map集合中的所有值得方法
- Java集合Set、List、Map的遍历方法
- java 遍历map 方法 集合 五种的方法
- java中List、Set、Map集合的遍历方法总结
- java 基础知识之遍历Map 方法集合
- Java遍历Map集合的三种方法
- java 遍历map 方法 集合 五种的方法
- java 遍历map 方法 集合 jackey
- Java集合Set、List、Map的遍历方法
- Java中遍历Map的两种方法:keySet和entrySet
- java中遍历Map集合的集中方法总结
- Java两种简单方式遍历Map集合
- java中Map集合遍历方法
- Java集合Set、List、Map的遍历方法
- Java集合Set、List、Map的遍历方法
- Java集合List、Set、Map的遍历方法