HashMap 我只会keySet()遍历 请大神用实例说明下 values() entrySet()遍历

import java.util.HashMap;

import java.util.Iterator;
class Shop{
private String bianhao;
private String mingchen;
private double jiage;
Shop(String bianhao,String mingchen,double jiage){
this.bianhao=bianhao;
this.mingchen=mingchen;
this.jiage=jiage;
}
public String getBianhao() {
return bianhao;
}
public void setBianhao(String bianhao) {
this.bianhao = bianhao;
}
public String getMingchen() {
return mingchen;
}
public void setMingchen(String mingchen) {
this.mingchen = mingchen;
}
public double getJiage() {
return jiage;
}
public void setJiage(double jiage) {
this.jiage = jiage;
}
}
public class Hashmap{
public static void main(String[]args){
HashMap hash=new HashMap();
Shop one=new Shop("001","苹果",33.1);
Shop two=new Shop("002","梨子",10.2);
Shop three=new Shop("003","芒果",13.8);
hash.put("001", one);
hash.put("002", two);
hash.put("003",three);
//一,用keySet()遍历
Iterator it=hash.keySet().iterator();
while(it.hasNext()){
String key=it.next().toString();
Shop shop1=(Shop)hash.get(key);
System.out.println("商品编号:"+shop1.getBianhao()+
"\t商品名称:"+shop1.getMingchen()+"\t商品价格:"+shop1.getJiage()+"元");
}
//请大神们帮我遍历下:
//二,用entrySet()遍历
//三,用values()遍历
}

}

http://blog.csdn.net/liu826710/article/details/9001254

  你可以直接再继续调用下这三个方法就知道是什么用的了,自己探索出的东西比直接拿来的记忆更深刻的。

/**
* 最常见也是大多数情况下用的最多的,一般在键值对都需要使用
 */
Map <String,String>map = new HashMap<String,String>();
map.put("熊大", "棕色");
map.put("熊二", "黄色");
for(Map.Entry<String, String> entry : map.entrySet()){
    String mapKey = entry.getKey();
    String mapValue = entry.getValue();
    System.out.println(mapKey+":"+mapValue);
}