HashMap是数组+链表的数据结构,put操作会先计算key的hashcode,如果不一样则放入entry数组,如果一样则在该hashcode的entry上生成链表。特点:默认容量,最大容量,扩容系数等等,扩容后还需要重新分别entry数组,因为hashcode变了,具体可看源码。
遍历方式:
1.String key : map.keySet()
2.Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
3.for (Map.Entry<String, String> entry : map.entrySet()) { }
4.for (String v : map.values()) {}