When should I use LinkedList
? When working with stacks mostly, or when working with buffers.When should I use ArrayList
? Only when working with indexes, otherwise you can use HashTable with linked list, then you get:
Hash table + linked list
- Access by key O(1),
- Insert by key O(1),
- Remove by key O(1)
- and there is a trick to implement RemoveAll / SetAll with O(1) when using versioning
It seems like a good solution, and in most of the cases it is, how ever you should know:HashTable takes a lot of disc space, so when you need to manage 1,000,000 elements list it can become a thing that matters. This can happen in server implementations, in clients it is rarely the case.
Also take a look at Red-Black-Tree
- Random access Log(n),
- Insert Log(n),
- Remove Log(n)