/*
 * 功能HashMap的使用
 * */
package com.jihe;
import java.util.HashMap;
import java.util.Iterator;
class hashmap{
    public static void main(String[] args){
        HashMap  hm=new HashMap();
        person p1 = new person("毛主席",100,"男");
        //插入一个元素
        hm.put("p1",p1);
        p1 = new person("普京",100,"男");
        hm.put("p2",p1);
        p1 = new person("奥巴马",50,"男");
        hm.put("p3",p1);
        if(hm.containsKey("p2")){
            System.out.println("p2在这里!他的名字是:"+((person)hm.get("p2")).getName());
        }else{
            System.out.println("p2不在这里!");
        }
          
        Iterator iter=hm.keySet().iterator();
        while(iter.hasNext()){
            //遍历输出hashmap数据
            String key=iter.next().toString();
            person ps=(person)hm.get(key);
            System.out.println(key+"元素:"+((person)ps).getName());
        }
    }
}