What is Performance of Various Java Collection Implementations/Algorithms? What is Big ‘O’ notation for each of them?

Each java collection implementation class have different performance for different methods, which makes them suitable for different programming needs. The performance of various Java collection implementations and algorithms can vary based on the specific use case and the operations being performed. The Big O notation is a way to express the time complexity of algorithms … Read more

Where will you use ArrayList and Where will you use LinkedList?

Below is a snippet from SUN’s site. The Java SDK contains 2 implementations of the List interface – ArrayList and LinkedList. If you frequently add elements to the beginning of the List or iterate over the List to delete elements from its interior, you should consider using LinkedList. These operations require constant-time in a LinkedList … Read more

What is the Difference Between ArrayList and LinkedList? (ArrayList vs LinkedList.

when the internal array fills up. The arrayList has to create a new array and copy all the elements there. The ArrayList has a growth algorithm of (n*3)/2+1, meaning that each time the buffer is too small it will create a new one of size (n*3)/2+1 where n is the number of elements of the … Read more

Which Implementation of the List Interface Provides for the Fastest Insertion of a new Element into the Middle of the List?

Vector, ArrayList, LinkedList ArrayList and Vector both use an array to store the elements of the list. When an element is inserted into the middle of the list the elements that follow the insertion point must be shifted to make room for the new element. The LinkedList is implemented using a doubly linked list; an … Read more

Set & List Interface Extend Collection, so Why doesn’t Map Interface Extend Collection

Though the Map interface is part of collections framework, it does not extend collection interface. This is by design, and the answer to this questions is best described in Sun’s FAQ Page: This was by design. We feel that mappings are not collections and collections are not mappings. Thus, it makes little sense for Map … Read more