首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

hashmap键值解决思路

2012-01-31 
hashmap键值请问怎样取得hashmap中所有关键字的值,谢谢[解决办法]map.keySet[解决办法]Map hmnew Hashmap

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());
}

热点排行