Java Collection Interview Questions – Updated for 2019


Here are the latest Java collection interview questions for your reference. Java Collections Framework is pivotal in developing high-performance, reusable and reliable Java applications.

Our team prepared this list after analyzing the question pattern of many IT companies hiring Java programmers.

If you like to test your Java coding skills, then try to get through the 30 Java coding interview questions.

Check out the top Java collection interview questions.

Top Java Collection Interview Questions

What is the use of Collection Framework in Java?

Java Collection Framework (JCF) represents a set of interfaces and classes which provide efficient ways to store and handle data in a Java application.

It includes several classes that support the following operations:

  • Searching,
  • Sorting,
  • Insertion,
  • Manipulation, and
  • Deletion.

💡 Fact – Java programming language is the brain-child of James Gosling who designed it in early 1995.

What are the main benefits of Collection Framework?

There are primarily four qualities that make Java Collections Framework extremely useful for the programmers.

Performance – Collection classes are highly efficient data structures to improve speed and accuracy.

Reusability – Collection classes can intermix with other types to promote reusability.

Maintainability – Supports consistency and interoperability in the implementation and hence makes the code easy to maintain.

Extensibility – Allows customization of primitive collection types as per the developer’s requirements.

What is the structure of Collection Framework in Java?

Below is the diagram picturing the different collection classes and interfaces.

Java Collection Interview Questions and Answers for Developers
Java Collection Framework Hierarchy.

What is the difference between Collection and Collections Framework?

Collection – A collection is an object container that can hold multiple elements and functions as a single unit.

Collections Framework – Collections framework provides a centralized system for managing and representing collections.

What is the difference between Collection and Collections?

  • The Collection is an interface while Collections is a Java class.
  • Both the Collection and Collections are part of <java.util> package and are the main components of the Java Collection Framework.

What is the root interface in the collection hierarchy?

It is Collection interface which is the root interface in the collection hierarchy. However, a few may disagree and will say that the Collection interface extends the Iterable interface. So Iterable must be the root interface.

But you can make the counter-argument by saying that the Iterable interface is a part of the <java.lang> package, not of the <java.util> package.

Also, the Oracle’s Java collections documentation states that Collection interface is a member of the Java Collections framework which belongs to the <java.util> package.

What are the primary interfaces in the Java Collections Framework?

Java Collections Framework comprises of five primary interfaces.

Collection Interface – Most of the collections in Java inherit from the Collection interface. It is the core of the collections framework and stays at the root of Collection’s hierarchy.

Set Interface – It is a mathematical interpretation of Set which doesn’t allow duplicate entries. Also, a set doesn’t define an order for the elements and hence doesn’t support the index-based search.

Queue Interface – This interface follows the principals of a queue and stores elements in the same order as they enter. Operations like addition will take place at the rear and removal from the front.

List Interface – A list is an extended form of an array.

Lists are ordered and can also contain duplicate elements. Not only it allows the index-based search, but insertion can also be done independently of the position.

Map Interface – Map is a two-dimensional data structure which stores data in the form of Key-Value pair. The map is necessarily a set and can’t have duplicate elements.

In a map, the value represents an element whereas the key is the hash code of the same item.

Which are the collection classes that are synchronized or thread-safe?

Following Collection classes are thread-safe and support synchronization. You can use them safely in a multi-threaded Java application.

Hashtable – A Hashtable is a collection class which stores lists as array elements also known as buckets. It associates the keys to values. None of the key or value can be null. And the keys are objects which are hashed to compute the hash code. The resultant works as the index to store the value within the table.

Vector – A Vector class serves as a dynamic array. It behaves like ArrayList with two main differences. The first is that a Vector is synchronized and secondly, it brings in some additional methods which are not part of the Collections Framework.

💡 Fact – A study reveals that more than 3 billion devices run on Java-based platforms.

What is the primary difference between List and Set?

List vs. Set.

  • Set holds unique elements whereas List can have duplicate items.
  • The Set is an unordered collection whereas List is the ordered one.
  • The List preserves the order of the object addition.

What is the principal difference between Map and Set?

Map object use unique keys to hold values whereas Set contains unique values.

Which are the classes that implement List and Set interface?

Following classes implement the List interface.

  • ArrayList,
  • Vector, and
  • LinkedList.

Following classes implement the Set interface.

What is an Iterator in the Java Collections Framework?

The Iterator is an interface. You can locate it in the <java.util> Package. It provides methods to iterate over any Collection.

What are the principal differences between Iterator and Enumeration?


  • Enumeration functions like a read-only interface as it only allows to traverse and retrieve the object.
  • Enumeration is doubly faster than the Iterator and uses very less memory.
  • Enumeration is very necessary and fulfills the primary requirements.


  • The Iterator is much safer than Enumeration as it always blocks other threads to alter the collection object.
  • Iterator gives the ability to remove elements using remove() method whereas Enumeration doesn’t.
  • Iterator method names are more logical to make their functionality clear.

What is the design pattern that Iterator uses?

  • It uses the iterator design pattern. Iterator design pattern enables the ability to sail through the collection of objects by using a standard interface abstracting the underlying implementation.
  • Enumeration is also an example of the Iterator design pattern.

What are the methods to override for you to use any object as a key in HashMap?

To use an object as the key in HashMap, you can implement equals() and hashCode() methods.

What is the main difference between Queue and Stack?

The Queue is a type of data structure which follows the FIFO (first in first out) mechanism.

An example of a Queue in the real world is casting your votes in the electoral center.

The Stack is a data structure which follows the LIFO (last in first out) mechanism.

A real-time example of Stack is when a person wears a bracelet set, the last bracelet worn is the first to get removed and the opening bracelet you would take out in the end.

💡 Fact – 95 percent of Software Enterprises use Java for development.

What is the best way to reverse a List in Collections?

The Collections class provides a reverse(List list) method which accepts the list as a parameter.

e.g. Collections.reverse(ListOfObject);

Which approach would you choose to convert the array of strings into the list?

There is one method in the Arrays class of java.util package as List() which takes the array as its parameter.

List<String> arrayList = new ArrayList<String>();
String [] strArr = arrayList.toArray(new String[arrayList.size()]);

The Collection interface doesn’t have a hasNext() or next() method. Can you explain why?

The Iterator interface does have the hasNext(), and next() methods, but the Collection interface doesn’t have them.

The Collection interface could have the hasNext(), and next() methods but more methods would have needed to reset the “built-in” iterator to allow iteration from the beginning. Such a mechanism would need two iterators while the Collection would only have one at any given time.

Hence, it doesn’t make sense to add it to the interface that everyone has to implement.

What is the difference between the Iterator and ListIterator?

  • You can use Iterator to traverse the collections like Set and List whereas ListIterator you can utilize with Lists only.
  • Using Iterator, you can cross in the forward direction only whereas ListIterator supports to traverse in both the direction.
  • ListIterator inherits from the Iterator interface and brings add-on functionalities like the ones listed below.
    • Adding an element,
    • Replacing an item, and
    • Retrieve the index position for the previous and next.

What is iterator’s fail-fast property?

  • Iterator fail-fast property verifies for any change that occurs in the structure of the underlying collection whenever you try to get the next element.
  • If it detects any change, it throws the ConcurrentModificationException.
  • All the Iterator implementations in the Collection classes are fail-fast by design except the concurrent collection classes like ConcurrentHashMap and CopyOnWriteArrayList.

What is the difference between Fail-fast and Fail-safe?

  • Fail-fast is nothing but the mechanism to support the instant reporting of any failure and whenever a problem occurs fail-fast system fails.
  • In Java, a fail-fast iterator may throw concurrent modification exception whereas a fail-safe iterator won’t.
  • The exception can occur due to one of the two reasons as given below.
    • When one of the threads is iterating through the collection while the other one is trying to modify it
    • Or after invoking the remove() method if you attempt to change the collection object

What are the different ways to sort a list of Objects?

Following methods can be applied to perform sorting.

  • To sort the array of objects, you can use Arrays.sort() method.
  • When you need to sort a collection of the objects, then use Collections.sort() method.

How does HashMap work in Java?

HashMap follows the concept of hashing. It employs put(key, value) and the get(key) methods to manage (storing and retrieving) the objects from the HashMap.

When we call the put() method with a key and value object, the HashMap mechanism triggers the hashCode() method on the principal object and returns the hash value. Then, the hashing function locates a bucket location using the hash value where it can save the key-value pair in the form of a nested class called Entry (Map.Entry).

When you need to fetch a value from the HashMap, you call the get() method with the desired key as the parameter. The critical object produces the same hash value which leads to the same bucket location where the object was stored in the put() method.

What is the difference between HashMap and Hashtable?

  • Synchronization or Thread Safe
  • Null keys and null values
  • Iterating the values
  • Default Capacity

Why doesn’t Map interface extend Collection interface?

  • The Set is an unordered collection and does not allow duplicate elements.
  • The List is ordered collection allows duplicate elements whereas the Map is a key-value pair.
  • It is viewed as a set of keys and a collection of values.
  • A Map is a collection of key-value pairs so by design they separated from collection interface.

What is the use of Properties class?

The Property is a subclass of Hashtable. You can use it to manage the list of values using the keys, both the key and value are of String type.

💡 Fact – Java tops the list of most popular programming languages as per the latest TIOBE index.

How to remove the redundant elements from an ArrayList object?

Here is the method to remove the redundant element from the ArrayList.

  • Offload all of the ArrayList elements to a LinkedHashSet.
  • Empty the ArrayList.
  • Copy all elements of LinkedHashSet to an ArrayList.

You can refer the below example for help.

import java.util.ArrayList;
import java.util.List;
import java.util.LinkedHashSet;
public class DeleteDuplicates {

  public static void main(String[] args) {
     /* Creating an ArrayList of Strings and adding
      * all elements to it
     List<String> arrlst = new ArrayList<String>();
     // Displaying the ArrayList elements 
     System.out.println("ArrayList contains: "+arrlst);
     // Creating a LinkedHashSet
     LinkedHashSet<String> linkhs = new LinkedHashSet<String>();
     /* Adding ArrayList elements to the LinkedHashSet
      * in order to remove the duplicate elements and 
      * to preserve the insertion order.
     // Removing the ArrayList elements
     // Adding the LinkedHashSet elements to the ArrayList
     // Displaying ArrayList elements
     System.out.println("ArrayList contains: "+arrlst);

Summary – Essential Java Collection Interview Questions

We wish that the above Java interview questions would help you in speed up preparations and hopefully, you would get the desired result.

However, if you like to drill into the collection framework, then see how you score in the below Java quiz.

Finally, if you found the Java collection interview questions worth your time, then extend your support and share this post.




Leave a Comment