Lists

CopyOnWriteArrayList<T>:

Thread-safe but too costly.

 

ArrayList<T>:

Creates an array of T with elements (default capacity is 10).
For adding 11th element it will create a new array with bigger element size (old >> 1 (divided by two), so it will be 15) and copy the original into it, the first array will be garbage collected.

It is worth adding an initial value to create ArrayList with huge number of element:

List<Book> books = new ArrayList<>(50000); 

 

Vector<T>:

Thread-safe List

Stack<T>:

It inherits from Vector<T> class. LIFO, DeQueue(Double ended queue)

LinkedList<T>:

It does not use array to store items, instead use pointers to add items to create an order in the linkedlist. Each node in the list points the next and the previous item in the list.

LinkedList .get(index) method always will be slower than ArrayList.get(index) because nodes of LinkedList stores only the next and the previous element references, however ArrayList can achieve its element in one step.

 

HashMap<K, V>:

When we instantiate a hasmap it is created in memory initally as an array with an initial capacity of sixteen elements (buckets). To put an element into the map it will use modulo of the key (xy%16, 16 is the bucket number, xy the hashcode). Every bucket contains a LinkedList of object. HashMap has something called factor, the value of the factor is 0.75 (three quarters). If three quareter of the buckets have one or more elements, hashmap will duplicate the buckets. So when the hashmap grows all value will be re-evaulated and will get into a different bucket, so this process a significant overhead.
Setting the size and the factor:

Map<String, Book> books = new HashMap<>(600000, 0.6f);

A good range of hashcodes very important because of the performance. 

 

LinkedHashMap<K,V>:

This will get back data in the same order how we have put them into the map. The performance is the same as the HashMap but this one eats a bit more memory.