1.Map的主要实现类
2.HashMap的实现原理
3.Map的常用方法
4.遍历Map集合的多种方式
public class MapTest { Map map = new HashMap(); @Test public void test1(){ map.put(123,"AA"); map.put(456,"BB"); map.put("cc",88); //获取所有Key Set<Object> set = map.keySet(); Iterator<Object> iterator = set.iterator(); while (iterator.hasNext()){ System.out.println(iterator.next()); } System.out.println("========================"); //获取所有value Collection<Object> list = map.values(); Iterator<Object> iterator1 = list.iterator(); while (iterator1.hasNext()){ System.out.println(iterator1.next()); } } @Test public void test2() { map.put(123, "AA"); map.put(456, "BB"); map.put("cc", 88); //遍历所有键值对 : 方式一 Set<Object> set = map.entrySet(); Iterator<Object> iterator = set.iterator(); while (iterator.hasNext()){ Object obj = iterator.next(); Map.Entry entry = (Map.Entry) obj; System.out.println(entry.getKey()+"--->"+entry.getValue()); } //遍历所有键值对 : 方式二 Set set1 = map.keySet(); Iterator iterator1 = set1.iterator(); while (iterator1.hasNext()){ Object key = iterator1.next(); Object value = map.get(key); System.out.println(key+"--->"+value); } //遍历所有键值对 : 方式三 for (Object key : map.keySet()) { System.out.println(key+"--->"+map.get(key)); } } }