当前位置: 代码迷 >> J2SE >> hashmap键值解决思路
  详细解决方案

hashmap键值解决思路

热度:212   发布时间:2016-04-24 15:40:59.0
hashmap键值
请问怎样取得hashmap中所有关键字的值,谢谢

------解决方案--------------------
map.keySet
------解决方案--------------------
Map hm=new Hashmap();
hm.put( "a ", "A ");

Iterator it = hm.entrySet().iterator();
while (it.hasNext()) {
Object key =it.next();//取出 "a "
Object value=hm.get(key);//取出 "A "
}


Map map = new HashMap();
map.set( "a ", "b ");
Iterator it = map.keySet().iterator();
while (it.hasNext()) {
Object key =it.next();
System.out.println( "key is "+key);//
System.out.println( "value is "+map.get(key));

}


------解决方案--------------------
Set set = hm.keySet();
Iterator it = set.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
  相关解决方案