Interview Questions on Collections in Java

When to use a Map in java?

Lists and Maps are different data structures. Maps are used for when you want to associate a key with a value and Lists are an ordered collection.

How does HashMap work?

Difference between Arraylist and Vector.

Difference between Arraylist and LinkedList.

When to use ArrayList and LinkedList?

Difference between HashMap and Hashtable.

Difference between HashMap and HashSet.

How can we sort a list of object based on it’s property?

Difference between Iterator and Enumeration interface in Java.

The functionality of Enumeration and the Iterator are almost the same. You can use remove() in an Iterator to remove any element, while Enumeration doesn’t provide remove() method. Using Enumeration, we can traverse and fetch the objects, whereas using Iterator, we can add and remove the objects as well. Therefore, Iterator can be useful if you want to manipulate the list and Enumeration is for read-only access. Also, Enumeration is only applicable for legacy classes e.g Hashtable, Vector.

How to iterate a HashMap?

Note that these questions are from the most recent interview confrontations and are the most relevant ones. 

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.