import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;

public class TestHashMap2 {
	// TODO Auto-generated method stub

			HashMap<String, Person>  map=new HashMap<String,Person>();
			
			map.put("first",new Person("刘翔", 35));
			
			map.put("second",new Person("呆萌", 18));
			
			Person person=map.get("second");
			
			System.out.println(person.getName());
			
			//遍历方法1
			
			//1.先返回 字典对 集合 字典对是由key和value组成的
			Set<Entry<String, Person>> set=  map.entrySet();
			
			//用加强for的方式遍历所有的字典对
			for(Entry<String, Person> en:set)
			{
				System.out.println(en.getKey());
				Person person2=en.getValue();
				System.out.println(person2);
			}
			
			//2.用迭代器
			Iterator<Entry<String, Person>> iterator=   set.iterator();
			
			while(iterator.hasNext())
			{
				Entry<String, Person> entry=iterator.next();
				
				System.out.println(entry);
				
			}
			
			
			
			
		}
}