1.聲明一個(gè)map: Map map = new HashMap();
2.向map中放值,注意:map是key-value的形式存放的.如:
map.put("sa","dd");
3.從map中取值:String str = map.get("sa").toString();結(jié)果是:str = "dd";
4.遍歷一個(gè)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() ;
}