Difference between Vector and Arraylist is the most common Core Java Interview question you will come across in Collection . This question is mostly used as a start up question by the Interviewers before testing deep roots of the Collection .
Vector , ArrayList classes are implemented using dynamically resizable array providing fast random access and fast list traversal very much like using an ordinary array . ArrayList support dynamic arrays that can grow as needed that is ArrayList can be dynamically increased or decreased in size .
Read Also : Difference between HashMap and ConcurrentHashMap
Arraylist vs Vector in Java
1. Synchronization and Thread-Safe
Vector is synchronized while ArrayList is not synchronized . Synchronization and thread safe means at a time only one thread can access the code .In Vector class all the methods are synchronized .Thats why the Vector object is already synchronized when it is created .
2. Performance
Vector is slow as it is thread safe . In comparison ArrayList is fast as it is non synchronized . Thus in ArrayList two or more threads can access the code at the same time , while Vector is limited to one thread at a time.
3. Automatic Increase in Capacity
A Vector defaults to doubling size of its array . While when you insert an element into the ArrayList , it increases
its Array size by 50% .
By default ArrayList size is 10 . It checks whether it reaches the last element then it will create the new array ,copy the new data of last array to new array ,then old array is garbage collected by the Java Virtual Machine (JVM) .
4. Set Increment Size
ArrayList does not define the increment size . Vector defines the increment size .
You can find the following method in Vector Class
public synchronized void setSize(int i) { //some code }
There is no setSize() method or any other method in ArrayList which can manually set the increment size.
5. Enumerator
Other than Hashtable ,Vector is the only other class which uses both Enumeration and Iterator .While ArrayList can only use Iterator for traversing an ArrayList .
6. Introduction in Java
java.util.Vector class was there in java since the very first version of the java development kit (jdk).
java.util.ArrayList was introduced in java version 1.2 , as part of Java Collections framework . In java version 1.2 , Vector class has been refactored to implement the List Inteface .
Please do mention in the comments in case if you have any doubts or suggestions regarding the post.
Difference Between Arraylist And Vector : Core Java Interview Collection Question
相關文章
- Difference between cursor and a ref cursor
- What is the difference between a Homemaker and a Housewife?
- java arrayList vector 區別Java
- Daily-Interview-Question[Title-Cover]AIView
- Java Collection介面 ArrayList集合(容器)Java
- Java List 常用集合 ArrayList、LinkedList、VectorJava
- java中的List介面(ArrayList、Vector、LinkedList)Java
- Java中Vector和ArrayList的區別Java
- Difference between Microsoft Dynamics 365 WEB API, Organization Service and Organization Data ServicROSWebAPI
- java複習之 Vector、ArrayList和LinkedList 的區別Java
- On-site question removal + direct interview | Meituan technical school recruitment live broadcast is here!REMViewUIAST
- Java Case InterviewJavaView
- LinkedList和ArrayList的區別、Vector和ArrayList的區別
- Java集合系列(二):ArrayList、LinkedList、Vector的使用方法及區別Java
- java集合【12】——— ArrayList,LinkedList,Vector的相同點與區別是什麼?Java
- What is the difference between Mysql InnoDB B+ tree index and hash index? Why does MongoDB use B-tree?MySqlIndexMongoDB
- List集合總結,對比分析ArrayList,Vector,LinkedList
- Java集合-CollectionJava
- 【java】【集合】List的三個子類—ArrayList、Vector、LinkedList的區別和聯絡Java
- Java™ 教程(Collection介面)Java
- [Java基礎]collectionJava
- JAVA集合-ArrayListJava
- Java集合——ArrayListJava
- 【java】【集合】去除ArrayList中的元素、ArrayList巢狀ArrayListJava巢狀
- 【JavaSE】集合類Collection集合Map集合的簡單介紹,List介面,中三個常用子類ArrayList、Vector、LinkedList之間的比較。Set介面。Java
- Java:Collection集合、泛型Java泛型
- 2021-2-28 Mark-Java Interview SimpleJavaView
- Java 集合之ArrayListJava
- Java集合之ArrayListJava
- 【Java集合】2 ArrayListJava
- Java集合(一) —— ArrayListJava
- [Java基礎]ArrayListJava
- Java ArrayList 與 LinkedListJava
- ArrayList、LinkedList和Vector的原始碼解析,帶你走近List的世界原始碼
- 【java】【集合】List、ListIterator、VectorJava
- Java Collection集合面試題Java面試題
- Java 的 Collection 與 List 集合Java
- Java——ArrayList原始碼解析Java原始碼