Notable Differences In Java Collections

A collection framework is a class library to handle group of objects. Collection framework is implemented in 'java.util package'. A collection object stores references of other objects.

Difference between arraylist and vector

Array ListVector
By default, arraylist object is not synchronizedBy default, vector object is synchronized
ArrayList increases its size every time by 50%(half)Vector increases its size every time by doubling it
In case of a single thread, using ArrayList is faster than the vectorIn case of multiple threads, using vector is advisable. With a single thread, vector becomes slow

Difference between hashmap and hashtable

HashMapHashtable
By default, hashmap object is not synchronizedBy default, hashtable object is synchronized
In case of a single thread, using hashmap is faster than the hashtableIn case of multiple threads, using hashtable is advisable. With a single thread, hashtable becomes slow
Hashmap allows null keys and null values to be storedHashtable does not allow null keys or values
Iterator in the hashmap is fail-fast. This means iterator will produce exception if concurrent updates are made to the hashmapEnumeration for the hashtable is not fail-fast. This means even if concurrent updations are done to hashtable, there will not be any incorrect results produced by the enumeration.

Difference between set and list

SetList
A set represents a collection of elements and order of elements may change in the setA list represents ordered collection of elements and list preserves the order of elements in which they are entered
Set will not allow duplicate values to be storedList will allow duplicate values
Accessing elements by their index is not possible in case of setsAccessing elements by index is possible in lists
Sets will not allow null elementsLists allow null elements to be stored

Subscribe For More Content