Performance of List Interface Implementations

LinkedList Performance of get and remove methods is linear time [ Big O Notation is O(n) ] – Performance of add and Iterator.remove methods is constant-time [ Big O Notation is O(1) ] ArrayList The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. [ Big O Notation is O(1) ] – … Read more

Performance of Set Interface Implementations

HashSet The HashSet class offers constant-time [ Big O Notation is O(1) ] performance for the basic operations (add, remove, contains and size), assuming the hash function disperses the elements properly among the buckets. Iterating over this set requires time proportional to the sum of the HashSet instance’s size (the number of elements) plus the … Read more

Performance of Map Interface Implementations

Hashtable An instance of Hashtable has two parameters that affect its performance: initial capacity and load factor. The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created. Note that the hash table is open: in the case of … Read more

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