package project;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class test_1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
HashMap<String, Tea> hm = new HashMap<>();
hm.put("1",new Tea("114", "君山银针", 1000));
hm.put("2",new Tea("115", "西湖龙井", 1200));
hm.put("3",new Tea("116", "信阳毛尖", 1400));
prt_1(hm);
System.out.println("============================");
prt_2(hm);
System.out.println("============================");
prt_3(hm);
System.out.println("============================");
prt_4(hm);
}
//HashMap遍历一
public static void prt_1(HashMap<String, Tea> hm)
{
Set<Map.Entry<String, Tea>> st = hm.entrySet();
Iterator<Map.Entry<String, Tea>> it = st.iterator();
while(it.hasNext())
{
Map.Entry<String, Tea> en = it.next();
System.out.println(en.getKey()+"\t"+en.getValue().getTno()+"\t"+en.getValue().getName()+"\t"+en.getValue().getPrice());
}
}
//HashMap遍历二
public static void prt_2(HashMap<String, Tea> hm)
{
for(Map.Entry<String, Tea> en : hm.entrySet())
{
System.out.println(en.getKey() + "\t" + en.getValue().getTno()+"\t"+en.getValue().getName()+"\t"+en.getValue().getPrice());
}
}
//HashMap遍历三
public static void prt_3(HashMap<String, Tea> hm)
{
Set<String> set = hm.keySet();
Iterator<String> it = set.iterator();
while(it.hasNext())
{
String key = it.next();
System.out.println(key+"\t"+hm.get(key).getTno()+"\t"+hm.get(key).getName()+"\t"+hm.get(key).getPrice());
}
}
//HashMap遍历四
public static void prt_4(HashMap<String, Tea> hm)
{
for(String key : hm.keySet())
{
System.out.println(key + "\t" + hm.get(key).getTno()+"\t"+hm.get(key).getName()+"\t"+hm.get(key).getPrice());
}
}
}