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?


http://howtodoinjava.com/2012/10/09/how-hashmap-works-in-java/

Difference between Arraylist and Vector.

http://www.jcombat.com/core-java/collections-in-java

Difference between Arraylist and LinkedList.

http://www.jcombat.com/core-java/collections-in-java

When to use ArrayList and LinkedList?

http://www.jcombat.com/core-java/collections-in-java

Difference between HashMap and Hashtable.

http://www.jcombat.com/core-java/collections-in-java

Difference between HashMap and HashSet.

http://www.jcombat.com/core-java/collections-in-java

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

http://www.jcombat.com/core-java/sort-an-arraylist-using-comparator-and-comparable-interface

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.