TOP Java Collections Interview Questions (Intermediate Level)
A summary of the most frequently asked Collections questions in all IT Industry interviews.

The questions given below are the most frequently asked question in IT Industries nowadays. Check out the summary of the most frequently asked questions categorized by Beginner, Intermediate, and advanced level in most of the IT industries. It doesn’t mean that these questions will actually be asked during your interview process, but yeah you can get a sense of what companies might ask you. If you want to add questions to this list — feel free to write in the comments/Response section.
Important: Please prepare all the questions so you can be confident when you need to answer any questions.
Java Collections Interview Question Categories…
- Beginner Level Questionnaires (0–2 years experience)
- Intermediate Level Questionnaires (1–3 years experience)
- Advanced level Questionnaires (3+ Experienced)

Intermediate Level Questionnaires (1–3 years experience)
1. How Hashmap works internally in java?
You can answer as “On the base of Hashing techniques”. It will make a good impression on the interviewer and so they might not ask you to explain about full internal working!
Hashing in its simplest form is a way to assigning a unique code for any variable/object after applying any formula/algorithm on its properties.
A true hash function must follow this rule –
“Hash function should return the same hash code each and every time when the function is applied on same or equal objects. In other words, two equal objects must produce the same hash code consistently.”
Anyway, you must be aware of “Internal working of HashMap”.
2. What is the difference between ArrayList, LinkedList, Vector and Stack?

3. What is the difference between Iterator and ListIterator.
Using Iterator we can traverse the list of objects in the forward direction. But ListIterator can traverse the collection in both directions that are forward as well as backward.
4. What is the difference between peek(), poll() and remove() method of the Queue interface?
- Both poll() and remove() methods are used to remove the head object of the Queue. The main difference lies when the Queue is empty().
- If the Queue is empty then the poll() method will return null. While in similar case , remove() method will throw NoSuchElementException .
- peek() method retrieves but does not remove the head of the Queue. If the queue is empty then the peek() method also returns null.
5. What is the difference between HashMap and Hashtable?
It is one of the most popular collections interview questions for java developers. Make sure you go through this once before appearing for the interview.
Main differences between HashMap and Hashtable are :
- HashMap allows one null key and any number of null values while Hashtable does not allow null keys and null values.
- HashMap is not synchronized or thread-safe while Hashtable is synchronized or thread-safe.
6. What is the difference between Array and ArrayList in Java?
This question checks whether the student understands the concept of the static and dynamic array. Some main differences between Array and ArrayList are :
- An array is static in size while ArrayList is dynamic in size.
- An array can contain primitive data types while ArrayList can not contain primitive data types.

Bonus Question: What is the difference between LinkedList and ArrayList in Java?
The main differences between LinkedList and ArrayList are:
- LinkedList is the doubly linked list implementation of the List interface, while, ArrayList is the resizable array implementation of the List interface.
- LinkedList can be traversed in the reverse direction using the descendingIterator() method provided by the Java API developers, while, we need to implement our own method to traverse ArrayList in the reverse direction.
7. What is the difference between HashSet and TreeSet?
The main differences between HashSet and TreeSet are :
- HashSet maintains the inserted elements in random order while TreeSet maintains elements in the sorted order
- HashSet can store the null object while TreeSet can not store the null object.
Here you can find the comparison of all Sets (All in one)

8.Arrange the following in the ascending order (performance): HashMap, Hashtable, ConcurrentHashMap, and Collections.SynchronizedMap
Hashtable < Collections.SynchronizedMap < ConcurrentHashMap < HashMap
9.What is the difference between HashMap and ConcurrentHashMap?
This is also one of the most popular java collections interview questions. Make sure this question is on your to-do list before appearing for the interview.
The main differences between HashMap and ConcurrentHashMap are:
- HashMap is not synchronized while ConcurrentHashMap is synchronized.
- HashMap can have one null key and any number of null values while ConcurrentHashMap does not allow null keys and null values.
10. Write java code showing insertion, deletion, and retrieval of HashMap object?
Do it yourself (DIY), if found any difficulty or doubts then please mention it in the comments.
11. What are Comparable and Comparator interfaces? List the difference between them?

Just remember, .compareTo() method is not in Comparator.
12. Why Map interface does not extend the Collection interface in Java Collections Framework?
One liner answer: Map interface is not compatible with the Collection interface.
Explanation: Since Map requires a key as well as value, for example, if we want to add key-value pair then we will use put(Object key, Object value). So there are two parameters required to add an element to the HashMap object. In Collection interface add(Object o) has only one parameter.
The other reasons are Map supports valueSet, keySet as well as other appropriate methods which have just different views from the Collection interface.
13. When to use ArrayList and LinkedList in the application?
ArrayList has a constant time search operation O(1). Hence, ArrayList is preferred when there are more get() or search operation.
Insertion, Deletion operations take constant time O(1) for LinkedList. Hence, LinkedList is preferred when there are more insertions or deletions involved in the application.
14. Write the code for iterating the list in different ways in java?
There are two ways to iterate over the list in java :
- using Iterator
- using for-each loop
15. What is the default capacity of mostly used java collections (like ArrayList and HashMap)?
Make sure you understand the difference between the terms size and capacity.
Size represents the number of elements stored currently. Capacity indicates the maximum number of elements a collection can hold currently.
Default capacity of ArrayList: 10
Default capacity of HashMap: 16
16. Why are multiple inheritances not supported in Java?
This is a really tough question to answer because your answer may not satisfy the Interviewer, in most cases Interviewer is looking for specific points and if you can bring them, they would be happy.
Ambiguity around Diamond problem
A foo()
/ \
B foo() C foo()
\ /
D foo()
In my opinion, even if we remove the top head of diamond class A and allow multiple inheritances we will see this problem of ambiguity.
Sometimes if you give this reason to the interviewer he asks if C++ can support multiple inheritances then why not Java. In that case, tell below second reason,
- multiple inheritances do complicate the design and create problems during casting, constructor chaining, etc.
- java avoids this ambiguity by supporting single inheritance with interfaces.
You May Also Like,
Java Collection - Beginner Questionnaire
Java Collections - Advanced Questionnaire

Get my stories in your feeds by subscribing to me, or become a vocal+ member to read all stories of thousands of other writers, participate in all challenges and get a payout with low fees and less payout threshold on Vocal Media.
© Originally Published on Top Collections — Java Interview Questions, also republished on Medium by Author Rakshit Shah (Me).
About the Creator
Rakshit Shah
I am Computer Engineer and love to make websites and software. I am really eager to know about anything. I am curious to read and write cool stuff.



Comments
There are no comments for this story
Be the first to respond and start the conversation.