黑马程序员技术交流社区

标题: Map集合的理解 [打印本页]

作者: shaoboguanzi    时间: 2015-3-18 18:53
标题: Map集合的理解
1,Map集合下有HashMap、HashTable、TreeMap三个子接口。

                 HashTable:底层数据结构是哈希表,不可以存入空健和空值。线程同步。

                 HashMap底层的数据结构也是哈希表。可以存入空健空值。线程非同步。

                  TreeMap底层的数据结构是二叉树。线程非同步,也可以用于给Map集合中的健进行排序。

Map集合中存入的是键值对。

2,Map集合元素的取出基本思想:将map集合转化为set集合。方法有两种:

        (1),使用keyset方法。

                Set<pp> sk=mh.keySet();返回的map中的键值。

                Iterator<pp> it=sk.iterator();

while(it.hasNext()) { pp p=it.next(); String value=mh.get(p); }

(2),使用entryset是将map中的key与value的映射关系放入set集合中。

                Set<Map.Entry<pp, String>> me=mh.entrySet();

Iterator<Map.Entry<pp, String>> itt=me.iterator();

while(itt.hasNext()) {

Map.Entry<pp, String> pa=itt.next(); pp ba=pa.getKey(); String str=pa.getValue();  }




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2