package cn.itcast_01;

import java.util.HashMap;
import java.util.Map;

/*
 * ÐèÇó£ºÎÒÃÇµÄÑ§ÉúÊÇÓÐÑ§ºÅºÍÐÕÃûµÈÐÅÏ¢µÄ¡£
 * it001	ÁÖÇàÏ¼
 * it002	Íõ×æÏÍ
 * it003	ÕÅÂüÓñ
 * ÓÃÎÒÃÇÄ¿Ç°ËùÑ§µÄÖªÊ¶£¬¿ÉÒÔÊµÏÖ¡£
 * °ÑÕâÁ½¸ö×÷ÎªÒ»¸öÀàµÄ³ÉÔ±±äÁ¿£¬È»ºóÓÃCollectionÌåÏµµÄ¼¯ºÏ´æ´¢¶ÔÏó¼´¿É¡£
 * µ«ÊÇÄØ£¬ÎÒÏë¸ù¾ÝÑ§ºÅÖ±½Ó¾ÍÄÜÕÒµ½ÈË£¬ÈçºÎÊµÏÖÄØ?Ò²ÊÇ¿ÉÒÔÊµÏÖµÄ£¬±éÀúµÄÊ±ºò£¬ÒÀ´Î±È½ÏÑ§ºÅ¼´¿É¡£È»ºóÑ§ºÅÕýÈ·µÄ£¬»ñÈ¡¸Ã¶ÔÏóµÄÐÕÃû±äÁ¿¡£
 * ËäÈ»ÊÇ¿ÉÒÔµÄ£¬µ«ÊÇÓÐµãµãÂé·³£¬ÒòÎªÎÒÃÇ²»¿ÉÄÜÃ¿´ÎÒªÕÒÒ»¸öÈË£¬¶¼ÖØÍ·±éÀúÒ»±é¡£
 * ¼ÙÈçÓÐÒ»ÖÖ¼¯ºÏ£¬ÄÜ¹»ÊµÏÖÑ§ºÅºÍÐÕÃûµÄ¶ÔÓ¦¹ØÏµ£¬ÎÒÃÇ¾ÍÄÜ¼òµ¥ºÜ¶àÁË¡£
 * Ò»¸öÑ§ºÅ¶ÔÓ¦×ÅÒ»¸öÐÕÃû£¬È»ºó¸ù¾ÝÑ§ºÅ¾ÍÄÜÖªµÀ¸ÃÐÕÃû¡£ÎªÁËÂú×ãÕâÑùµÄÐèÇó£¬java¾ÍÌá¹©ÁËÒ»¸öÐÂµÄ¼¯ºÏ£ºMap¡£
 * 
 * Map£ºÔªËØÊÇ°´ÕÕ¼üÖµ¶ÔÐÎÊ½´æ´¢µÄ¡£Ã¿Ò»¶ÔÔªËØÓÉÁ½²¿·Ö×é³É¡£·Ö±ð½Ð¼üºÍÖµ
 * 	          ¼üÊÇÎ¨Ò»µÄ£¬ÖµÊÇ¿ÉÒÔÖØ¸´µÄ¡£
 * 	         ËùÒÔMap¼¯ºÏµÄµ×²ãÊý¾Ý½á¹¹ÊÇÕë¶Ô¼üÓÐÐ§£¬¸úÖµÎÞ¹Ø¡£
 * 
 * Map½Ó¿ÚºÍCollection½Ó¿ÚµÄ²»Í¬?(ÃæÊÔÌâ)
 * 		A:Map¼¯ºÏÊÇË«ÁÐ¼¯ºÏ£»Map¼¯ºÏµÄ¼üÊÇÎ¨Ò»µÄ£¬ÖµÊÇ¿ÉÒÔÖØ¸´µÄ¡£ÆäÊµÎÒÃÇÒ²¿ÉÒÔ¼òµ¥µÄÀí½âÎªMap¼¯ºÏµÄ¼üºÍÖµÊÇÓÉSetºÍList×é³É£»Êý¾Ý½á¹¹Õë¶Ô¼üÓÐÐ§¡£
 * 		B:Collection¼¯ºÏÊÇµ¥ÁÐ¼¯ºÏ£»Collection¼¯ºÏµÄ¶ù×ÓSetÊÇÎ¨Ò»µÄ£¬ListÊÇ¿ÉÒÔÖØ¸´µÄ£»Êý¾Ý½á¹¹Õë¶ÔÔªËØÓÐÐ§¡£
 * 
 * Map¼¯ºÏµÄ¹¦ÄÜ£º
 * 		A:Ìí¼Ó¹¦ÄÜ
 * 			V put(K key,V value):Ìí¼Ó£¬Ìæ»»»òÕßÐÞ¸Ä¡£¼ü²»Í¬£¬Ìí¼Óµ½¼¯ºÏ¡£¼üÏàÍ¬£¬ÖµÌæ»»¡£
 * 		B:ÒÆ³ý¹¦ÄÜ
 * 			void clear():ÒÆ³ýËùÓÐÓ³Éä¹ØÏµ
 * 			V remove(Object key):¸ù¾Ý¼üÒÆ³ý¼üÖµ¶ÔÔªËØ£¬·µ»ØµÄÊÇ¼ü¶ÔÓ¦µÄÖµ
 * 		C:ÅÐ¶Ï¹¦ÄÜ
 * 			boolean containsKey(Object key):ÅÐ¶ÏMap¼¯ºÏÖÐÊÇ·ñ°üº¬Ö¸¶¨µÄ¼ü
 * 			boolean containsValue(Object value):ÅÐ¶ÏMap¼¯ºÏÖÐÊÇ·ñ°üº¬Ö¸¶¨µÄÖµ
 * 			boolean isEmpty():ÅÐ¶Ï¼¯ºÏÊÇ·ñÎª¿Õ
 * 		D:»ñÈ¡¹¦ÄÜ
 * 			Set<Map.Entry<K,V>> entrySet():·µ»ØµÄÊÇ¼üÖµ¶Ô¶ÔÏóµÄSet¼¯ºÏ¡£
 * 			V get(Object key):¸ù¾Ý¼ü»ñÈ¡Öµ
 * 			Set<K> keySet():ËùÓÐµÄ¼üµÄ¼¯ºÏ
 * 			Collection<V> values():ËùÓÐÖµµÄ¼¯ºÏ
 * 			int size():¼¯ºÏµÄ³¤¶È
 */
public class MapDemo {
	public static void main(String[] args) {
		// ´´½¨¼¯ºÏ¶ÔÏó
		// ´´½¨ÔªËØ
		// Ìí¼ÓÔªËØ
		// ±éÀú¼¯ºÏ

		// ´´½¨¼¯ºÏ¶ÔÏó
		Map<String, String> map = new HashMap<String, String>();

		// Ìí¼ÓÔªËØ
		// V put(K key,V value)
		// System.out.println("put:" + map.put("ÎÄÕÂ", "ÂíÒÁÀþ"));
		// System.out.println("put:" + map.put("ÎÄÕÂ", "Ò¦µÑ"));
		map.put("ÎÄÕÂ", "ÂíÒÁÀþ");
		map.put("Ð»öª·æ", "ÕÅ°ØÖ¥");
		map.put("ÌïÁÁ", "Ò¶Ò»Üç");
		map.put("Íô·å", "ÕÂ×Óâù");

		// void clear():ÒÆ³ýËùÓÐÓ³Éä¹ØÏµ
		// map.clear();

		// V remove(Object key):¸ù¾Ý¼üÒÆ³ý¼üÖµ¶ÔÔªËØ£¬·µ»ØµÄÊÇ¼ü¶ÔÓ¦µÄÖµ
		// System.out.println("remove:" + map.remove("Íô·å"));
		// System.out.println("remove:" + map.remove("Íô·å2"));

		// boolean containsKey(Object key):ÅÐ¶ÏMap¼¯ºÏÖÐÊÇ·ñ°üº¬Ö¸¶¨µÄ¼ü
		// System.out.println("containsKey:" + map.containsKey("ÌïÁÁ"));
		// System.out.println("containsKey:" + map.containsKey("É­µú"));

		// boolean isEmpty():ÅÐ¶Ï¼¯ºÏÊÇ·ñÎª¿Õ
		// System.out.println("isEmpty:" + map.isEmpty());

		// int size():¼¯ºÏµÄ³¤¶È
		System.out.println("size:" + map.size());

		System.out.println("map:" + map);
	}
}
