Skip to content

Commit 48f5eef

Browse files
authored
Update README.md
1 parent 973965d commit 48f5eef

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

README.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@ 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.
2020

21-
## ```HashMap```
22-
Can store key-value pairs. Implements the ```Map``` interface. Creates a lookup table where values can be looked up based on keys. Does not maintain order!
21+
## Maps
22+
Maps store key-value pairs. Implement the ```Map``` interface.
23+
* ```HashMap```: Does not maintain order.
24+
* ```LinkedMap```: Behind this there is a doubly linked list. This maintains the order.
25+
* ```TreeMap```: Will sort the keys in natural order.
26+
27+
## Sets
28+
Sets contain elements uniquely. (The same element cannot be in the set more than once.)
29+
* ```HashSet```: does not retain order
30+
* ```LinkedHashSet```: keeps the order of insertion
31+
* ```TreeSet```: Sorts in natural order
32+
Set operations like intersection, difference are implemented for sets (```retainAll```, ```removeAll```).
2333

24-
## Sorted maps: ```LinkedMap``` and ```TreeHashMap```

0 commit comments

Comments
 (0)