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()遍历
}
}
HashMap 我只会keySet()遍历 请大神用实例说明下 values() entrySet()遍历
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
悬赏问题
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog