What is basic Difference Between ArrayList and Vector in Java? Every java developer should know the answer of this questions.
There is nothing wrong or right to implementation, so it completely depends on what you need and what you want to achieve. The interviewer asked this type of question to check the basics fundamental things of the candidate and slowly they increase the level of question and time on the candidate.
Difference between ArrayList and Vector in Java
In this interview series of differences between, I tried to cover basics Difference Between ArrayList and Vector in Java. Vector vs ArrayList is one of the important questions for cracking the entry level of developer to check whether you know the basic building block of Java or not.
- Synchronization: Vector is syncronized while ArrayList is not synchronized List.
Vectoris synchronized means it’s method are synchronized , while
ArrayListis not synchronized it means its method not.
- Threadsafe: Vector is thread safe while arrayList is not thread safe
- Growth: Vector has double its size while ArrayList is its half of its size. Vector grows to double in size of its array when exceeds its size while adding , while
ArrayListgrows half i.e. 50% of its size
- Version: Vector is present since JDK 1.0 version while ArrayList added in JDK 1.2 version. vector class refactored tolist in 1.2 of jdk
Differences between some java classes
You can visit other differences between two java classes:
- Difference between HashMap and ConcurrentHashMap in java
- Difference Between HashMap and HashSet in Java
- HashMap Vs HashTable Vs SynchronizedMap Vs ConcurrentHashMap in Java
Write your suggestions to improve this post. Happy Learning for ArrayList vs vector in Java.