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
相關文章
- Java中Collection Frame中常用集合簡析(ArrayList,Vector,HashSet,TreeSet...)Java
- The main difference between Java & C++(轉載)AIJavaC++
- java arrayList vector 區別Java
- What is the difference between <%, <%=, <%# and -%> in ERB in Rails?AI
- Some difference between mysql & oracleMySqlOracle
- Java Collection介面 ArrayList集合(容器)Java
- 2017---Interview questionView
- Whats the difference between the v$sql* viewsSQLView
- Difference between business area and profit center
- What is the difference between gross sales and revenue?ROS
- The difference between literal and label.
- Daily-Interview-Question[Title-Cover]AIView
- ArrayList 和 Vector 的區別 -JAVAJava
- Difference between prop and attr in different version of jqueryjQuery
- What is the difference between restoring and recoveringREST
- Java中Vector和ArrayList的區別Java
- Java List 常用集合 ArrayList、LinkedList、VectorJava
- Java 集合 ArrayList VS LinkedList VS VectorJava
- What is the difference between application server and web server?APPServerWeb
- Difference between sap_all and sap_new
- 【Oracle】-Difference between Instance recovery and Crash RecoveryOracle
- SAP Difference between Credit memo and subsequent debits/credits
- java中的List介面(ArrayList、Vector、LinkedList)Java
- vector和iterator及collection
- Java中Vector與ArrayList的區別詳解Java
- Vector和ArrayList的區別
- java複習之 Vector、ArrayList和LinkedList 的區別Java
- Arraylist與Vector的區別 - Java那些事兒專欄Java
- Difference between Microsoft Dynamics 365 WEB API, Organization Service and Organization Data ServicROSWebAPI
- Python中print用法及The difference between Python 2 and 3Python
- Difference between 2>&-, 2>/dev/null, |&, &>/dev/null, >/dev/null, 2>&1devNull
- Java 容器和泛型(2)ArrayList 、LinkedList和Vector比較Java泛型
- On-site question removal + direct interview | Meituan technical school recruitment live broadcast is here!REMViewUIAST
- ARRAYLIST VECTOR LINKEDLIST 區別與用法
- LinkedList和ArrayList的區別、Vector和ArrayList的區別
- Java Case InterviewJavaView
- Java集合系列(二):ArrayList、LinkedList、Vector的使用方法及區別Java
- java集合【12】——— ArrayList,LinkedList,Vector的相同點與區別是什麼?Java