0%

Map学习

Map学习手记

Map结构特性.

实现类

HashMap

特点

  • HashMap类是基于哈希表的map接口的实现,并且允许使用null键和null值
  • HashMap实现了Map并扩展了AbstractMap类,本身并没有增加新的方法
  • 散列映射不保证元素的顺序,元素加入容器的顺序和读取的顺序可能并不相同,而且不保证顺序是恒久不变

构造方法

1
2
3
4
5
6
7
8
9
10
11
12
HapMap();
HapMap(Map m);
HapMap(int capacity);
/**
* Constructs an empty <tt>HashMap</tt> with the specified initial
* capacity and load factor.
* @param initialCapacity the initial capacity 初始化的容量
* @param loadFactor the load factor 扩展因子 TODO待理解
* @throws IllegalArgumentException if the initial capacity is negative
* or the load factor is nonpositive
*/
HapMap(int capacity,float loadFactor);

关键函数

1
2
3
4
5
6
public boolean isEmpty();
public V get(Object key);
public V put(K key, V value)
public V remove(Object key)
public Set<K> keySet()
public abstract Set<Entry<K,V>> entrySet();

hashmap put method