package 集合;
import java.util.*;
public class 向量 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        //创建一个hashmap对象
        HashMap hm=new HashMap();
        Emp emp2=new Emp("02","bb",4.2f);
        Emp emp1=new Emp("01","aa",3.4f);
        Emp emp3=new Emp("03","cc",5.5f);
        //将EMP添加到hm
        hm.put("01", emp1);
        hm.put("02", emp2);
        hm.put("03", emp3);
        //如果你要查找编号是01
        if(hm.containsKey("01"))
        {
            System.out.println("ok");
            //找到了如何取出键值对
            Emp emp=(Emp)hm.get("01");
            System.out.println("名字是:"+emp.getName());
            
        }
        else
        {
            System.out.println("no");
        }
        //遍历HashMap所有的key和value
        //Iterator迭代器
        Iterator it=hm.keySet().iterator();
        //hasNext看看是否又下一个返回一个布尔值
        while(it.hasNext())
        {
            //取出KEy
            String key=it.next().toString();
            //通过key取出value
            Emp emp=(Emp)hm.get(key);
            System.out.println("名字是:"+emp.getName());
            System.out.println("薪水是:"+emp.getSal());
            
        }
        
        
    }

}