Java Collections Tutorial 03 | List - Vector in java | java9s.com

preview_player
Показать описание
In this short presentation, i am going to talk about some differences between ArrayList and Vector.
If you take a look at their Hierarchies, both of them implement List and Collection interfaces. So, they both offer same functionality.
Infact Vector was the first implementation of the List and was introduced in Java 1.0 and ArrayList was introduced later in Java 1.2 or what is called as Java 2.0
So, what was the need to introduce ArrayList to the Collections, when Vector was already available for us.
This is where a most frequently asked interview question raises. What is the difference between a Vector and ArrayList?
Vector is thread safe and ArrayList is not.
ArrayList can be manipulated by multiple threads
vector allows only one thread to modify elements at any given time.

arraylist tries to grow by half of its size.But vector grows double in size whenever we try to add something
ArrayList is used in applications where multiple threads are needed. That is the reason why all the Java Enterprise Edition projects use ArrayList.
Рекомендации по теме
Комментарии
Автор

For multiple thread reading only operation, ArrayList is best.. For Multiple threads writing, Vector is best or you should use synchronized ArrayList. Correct me if I am wrong.

boopathirajagopalan
Автор

This is generally quite good, but yeah from 2:36 to 3:10 or so you reversed when you would use Vector vs. ArrayLIst. Also, most modern practice recommendations are NEVER USE VECTOR anymore, if you think you need it grab a wrapped ConcurrentArrayList from Collections instead.

jvsnyc
Автор

Hey correct me if I am wrong, We use ArrayList in single threaded environment and vector in multithreaded environment right?

sumeetvandakudri
Автор

Hii,
Sir, I understood ArrayList and Vector..But My question is that How work ArrayList in Programming and how work Vector in Programming..bcoz i m not able understand in programming.. i know about ArrayList and Vector..And most important question..ArrayList is by default Non-synchronized so that how is work non-synchronized in programming..and Vector is by default synchronized and how is work? But I know synchronized and non-synchronized.. I want know how these two collection work with sysnchonized and non-synchronized..plzzz give me ans immediately..

faizanahmed