可以自己去看看跟着jdk来的源代码?(全部是用java写的)就比较明白了!
我以前上学时的作业就是implement collection然后做一个myarraylist and mylinkedlist要求和arraylist和linkedlist是相同的,即的话了好几个通宵才把那30几个method全部写完总体来说arraylist 和 vector 是没有区别的j2se doc上面很清楚地说
The arraylist class is roughly equivalent to Vector, except that it is unsynchronized.
及多个线程同时使用一个arraylist时,当又一个线程改变了arraylist的内容时
需要用Collections.synchronizedList来同步hashtable and hashmap
1. hashtable is synchronized hashmap is not
2. hashmap 的 iterator 是failsafe的 而hashtable 的 enumerator 不是
就是说你初始化了你的hashmap.iterator()以后 如果改变了hashmap的内容
(iterator.remove()除外)iterator 会 throw 一个ConcurrentModificationException
这也是vector.enumerator()和arraylist.iterator()的区别
3. hashmap可以使用null当内容hashtable不行
我以前上学时的作业就是implement collection然后做一个myarraylist and mylinkedlist要求和arraylist和linkedlist是相同的,即的话了好几个通宵才把那30几个method全部写完总体来说arraylist 和 vector 是没有区别的j2se doc上面很清楚地说
The arraylist class is roughly equivalent to Vector, except that it is unsynchronized.
及多个线程同时使用一个arraylist时,当又一个线程改变了arraylist的内容时
需要用Collections.synchronizedList来同步hashtable and hashmap
1. hashtable is synchronized hashmap is not
2. hashmap 的 iterator 是failsafe的 而hashtable 的 enumerator 不是
就是说你初始化了你的hashmap.iterator()以后 如果改变了hashmap的内容
(iterator.remove()除外)iterator 会 throw 一个ConcurrentModificationException
这也是vector.enumerator()和arraylist.iterator()的区别
3. hashmap可以使用null当内容hashtable不行
ArryList跟Vector的区别除了接口
功能大体一致,最主要的区别是ArrayList是非同步的数据结构
HashMap跟Hashtable也是差不多,HashMap不是同步的结构
如何同步ArrayList和HashMap可以用
Collections.synchronizedList
Collections.synchronizedMap
方法
Vector采用同步结构,所以建议使用Vector
如果需要线程安全用Vector
引用《JAVA编程思想》:HashTable和HashMap极为相似,甚至连函数名称都相像。因此在新程序中,没有理由使用HashTable来取代HashMap.
Vector和Hashtable是线程同步的。而ArrayList和HashMap不是。但新的容器框架的Collections类可以解决这个问题。