您的位置:首页
hashmap和hashtable,arraylist和vector的区别
2016-11-13 12:10
501 查看
hashmap线程不安全,hashtable线程安全
hashmap允许使用 null 值和 null 键。(除了非同步和允许使用 null 之外,HashMap 类与 Hashtable 大致相同。)此类不保证映射的顺序,特别是它不保证该顺序恒久不变。
hashtable任何非
arraylist线程不安全,vector线程安全
arraylist和vector的初始大小都是10.
vector:向量的大小大于其容量时,容量自动增加的量。如果容量的增量小于等于零,则每次需要增大容量时,向量的容量将增大一倍。
Arraylist默认扩充1.5倍。
JDK1.6中的源码:
hashmap允许使用 null 值和 null 键。(除了非同步和允许使用 null 之外,HashMap 类与 Hashtable 大致相同。)此类不保证映射的顺序,特别是它不保证该顺序恒久不变。
hashtable任何非
null对象都可以用作键或值。为了成功地在哈希表中存储和获取对象,用作键的对象必须实现
hashCode方法和
equals方法。
arraylist线程不安全,vector线程安全
arraylist和vector的初始大小都是10.
vector:向量的大小大于其容量时,容量自动增加的量。如果容量的增量小于等于零,则每次需要增大容量时,向量的容量将增大一倍。
Arraylist默认扩充1.5倍。
JDK1.6中的源码:
// 确定ArrarList的容量。 // 若ArrayList的容量不足以容纳当前的全部元素,设置 新的容量=“(原始容量x3)/2 + 1” public void ensureCapacity(int minCapacity) { modCount++; // 将“修改统计数”+1 int oldCapacity = elementData.length; if (minCapacity > oldCapacity) { Object oldData[] = elementData; int newCapacity = (oldCapacity * 3)/2 + 1; if (newCapacity < minCapacity) newCapacity = minCapacity; elementData = Arrays.copyOf(elementData, newCapacity); } }
相关文章推荐
- Collection,Map,HashMap,hashTable,TreeMap,List,Vector,ArrayList的区别
- List和ArrayList和Vector和HashTable和HashMap区别
- Java容器类List、ArrayList、Vector及map、HashTable、HashMap的使用与区别
- ArrayList Vector Hashtable HashMap的区别
- Java容器类List、ArrayList、Vector及map、HashTable、HashMap的区别与用法
- hashset hashmap hashtable arraylist vector 区别
- Java容器类List、ArrayList、Vector及map、HashTable、HashMap的区别与用法
- Java容器类List、ArrayList、Vector及map、HashTable、HashMap的区别与用法
- Collection,Map,HashMap,hashTable,TreeMap,List,Vector,ArrayList的区别
- Vector 与 ArrayList,Hashtable 与 HashMap,Iterator 与 Enumeration的区别
- Java容器类List、ArrayList、Vector及map、HashTable、HashMap的区别与用法
- ArrayList和Vector的区别,HashMap和Hashtable的区别
- HashTable、HashMap、Vector、ArrayList之间的区别
- Hashtable和HashMap的区别 Vector、ArrayList和List的异同(笔记) 《转》
- Java容器类List、ArrayList、Vector及map、HashTable、HashMap分别的区别
- List、ArrayList、Vector及map、HashTable、HashMap的区别与用法
- Java知识点Vector和ArrayList,Hashtable和HashMap,ArrayList和LinkedList的区别
- Java容器类List、ArrayList、Vector及map、HashTable、HashMap的区别【转】
- (List和ArrayList和Vector和HashTable和HashMap区别)- -
- ArrayList和Vector的区别,HashMap和Hashtable的区别以及线程安全的理解【转】