Hashmap以键取值

来源:百度知道 编辑:UC知道 时间:2024/06/25 04:23:13
能介绍一下吗?

haspMap是由Key跟Value组成的
如果要从hashMap里取数据
当你只取Key时,可以这么做
Iterator ite = keySet.iterator();
while(ite.hasNext()){
System.out.println(ite.next());
}

只取Value时,这么做
Collection values = hm.values();
ite = values.iterator();
while(ite.hasNext()){
System.out.println(ite.next());
}

都取出来可以这么做
Set content = hm.entrySet();
ite = content.iterator();
while(ite.hasNext()){
System.out.println(ite.next());
}