package ch09_08;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class MapTest {

	public static void print(Map<Integer, String> map) {
		map.put(1, "张三");
		map.put(3, "王五");
		map.put(2, "李四");
		Set<Integer> set = map.keySet();//获取map对象中键的集合
		for (Integer key : set) {
			System.out.println(key + ":" + map.get(key));
		}
		System.out.println("-----------");
	}
	
       //采用3种不同的Map实现类存贮相同的对象，但存放顺序不同
	public static void main(String[] args) {
		System.out.println("HashMap 存放对象次序：");
		print(new HashMap<Integer, String>());
		System.out.println("LinkedHashMap存放对象次序：");
		print(new LinkedHashMap<Integer, String>());
		System.out.println("TreeMap存放对象次序：");
		print(new TreeMap<Integer, String>());
	}
}
