Skip to content

Commit 8429a7b

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 8369c95 + f12bb3d commit 8429a7b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ Lists implement the ```List``` interface:
1717
Basic rules of thumb for ```ArrayList``` and ```LinkedList```:
1818
* ```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.
1919
* ```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.*
27+
>
28+
> (https://stackoverflow.com/questions/2986296/what-are-the-differences-between-arraylist-and-vector)
2029
2130
## Maps
2231
Maps store key-value pairs. Implement the ```Map``` interface.
@@ -31,3 +40,17 @@ Sets contain elements uniquely. (The same element cannot be in the set more than
3140
* ```TreeSet```: Sorts in natural order
3241
Set operations like intersection, difference are implemented for sets (```retainAll```, ```removeAll```).
3342

43+
## Queues
44+
FIFO list.
45+
* ```LinkedList``` also implements ```Queue``` interface
46+
* ```ArrayBlockingQueue``` has a fix size which can be specified in the constructor
47+
48+
## Iterators
49+
* Classical way: ```Iterator```
50+
* Can remove elements during iteration
51+
* Navigation forward only (```next()``` method)
52+
* Modern way: foreach loop
53+
* Cannot change the list during iteration
54+
* Alternative way: ```ListIterator```
55+
* Can change the list during iteration (```remove()```, ```set()```, ```add()```)
56+
* More methods (for example, ```hasPrevious```, ```previous```)

0 commit comments

Comments
 (0)