You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,15 @@ Lists implement the ```List``` interface:
17
17
Basic rules of thumb for ```ArrayList``` and ```LinkedList```:
18
18
*```ArrayList``` is like an array. Meaning that removing entries from the end is fast - internally only the length of the array is shortened. But adding or removing entries from the beginning is slow - internally this means copying all the remaining entries to a new array. If you only want to add or remove items in the end of your list, use ```ArrayList```. ```ArrayList``` manages array internally. Accessing elements by index is very fast. Adding item at the beginning takes long time because the items need to be shifted. Near to the end it is faster, because less elements need to be shifted.
19
19
*```LinkedList```: this is based on doubly linked list data structure. If you want to add or remove items anywhere in the list, also in the middle, use ```LinkedList```. If you add items near the end of the list, ```ArrayList``` can be more efficient than ```LinkedList```. In ```LinkedList```, each element stores a reference to the previous and to the next element. To get an item at a particular index can be slower, because the list needs to iterate until that item. But adding an item anywhere is fast, because the links need to be changed, but shifting is not needed.
20
+
*```Vector```: it is very similar to ```ArrayList```. The main differences are:
21
+
*```Vector``` is synchronized, ```ArrayList``` is not
22
+
* handling of growth of the stored data is different
23
+
*```Stack```: inherited from ```Vector```.
24
+
> *Internally, both the ```ArrayList``` and ```Vector``` hold onto their contents using an ```Array```. When an element is inserted into an ```ArrayList``` or a ```Vector```, the object will need to expand its internal array if it runs out of room. A ```Vector``` defaults to doubling the size of its array, while the ```ArrayList``` increases its array size by 50 percent.*
25
+
>
26
+
> *If multiple threads access an ```ArrayList``` concurrently then we must externally synchronize the block of code which modifies the list either structurally or simply modifies an element. Structural modification means addition or deletion of element(s) from the list. Setting the value of an existing element is not a structural modification.*
0 commit comments