Update index.md (#29218)

Added reason to choose Vectors or Arraylist (in terms of synchronization)
This commit is contained in:
Shamp
2019-06-27 23:37:58 +05:30
committed by Randell Dawson
parent aec887be68
commit 307b0dedb3

View File

@ -102,9 +102,9 @@ for(Object obj : arr) {
An ArrayList allows us to randomly access elements. ArrayList is similar to *Vector* in a lot of ways, but it is faster than Vectors. The main thing to note is that - Vectors are faster than arrays but ArrayLists are not.
So when it comes down to choosing between the two - if speed is critical then Vectors should be considered, otherwise ArrayLists are better when it comes to storing large number of elements and accessing them efficiently.
## Basic Big O for ArrayList Methods:
So when it comes down to choosing between the two - if speed is critical then Vectors should be considered for a small set of items, otherwise ArrayLists are better when it comes to storing large number of elements and accessing them efficiently. Vectors are synchronized and arraylist are not, thats why choose vector for frequent update of elements otherwise Arraylist is efficient for traversing.
## Basic Big O for ArrayList Methods:
`.get(int index)`
- O(1). This will always be constant time.
@ -120,6 +120,5 @@ So when it comes down to choosing between the two - if speed is critical then Ve
It is important to understand the Big O for methods of data structures. This way, you can choose the most efficient data structure for your program.
#### More Information
- [ArrayList Documentation](https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html)