01 logo

TOP 30+ Java Collections Interview Questions (Beginner Questions)

A summary of the most frequently asked Collections questions in all IT Industry interviews.

By Rakshit ShahPublished 3 years ago Updated 3 years ago 5 min read
1
Java collections interview questions | Image by Author, prepared with MS PowerPoint

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)

Beginner Level Questionnaires (0–2 years experience)

1. What is Collection? What is a Collections Framework? What are the pros and cons of the Java Collections Framework?

Collection: A collection (also called a container) is an object that groups multiple elements into a single unit.

Collections Framework: Collection framework provides a unified architecture for manipulating and representing collections.

Pros/Benefits of Collections Framework :

1. Improves program quality and speed

2. Increases the chances of reusability of software

3. Decreases programming effort.

Cons/Disadvantages of collections framework:

1. It must cast to correct type.

2. It can’t be done compile-time type checking.

A Java collection framework provides an architecture to store and manipulate a group of objects. A Java collection framework includes the following:

  • Interfaces: Interface in Java refers to the abstract data types. They allow Java collections to be manipulated independently from the details of their representation. Also, they form a hierarchy in object-oriented programming languages.
  • Classes: Classes in Java are the implementation of the collection interface. It basically refers to the data structures that are used again and again.
  • Algorithm: Algorithm refers to the methods which are used to perform operations such as searching and sorting, on objects that implement collection interfaces. Algorithms are polymorphic in nature as the same method can be used to take many forms or you can say perform different implementations of the Java collection interface.

2. What is the difference between Collection and Collections?

The Collection is an interface while Collections is a java class, both are present in java.util package and part of the java collections framework.

You can find the major difference (like type, extends, static methods) and similar points between collection and collections here.

This question has been used to test the knowledge of the Java Collections Framework. Make sure you go through this question before appearing for the interview.

Collection vs Collections — java interview questions | Image by Author

3. Which collection classes are synchronized or thread-safe?

Vector, Stack, Hashtable, Properties and can be used in a multi-threaded environment because they are synchronized classes (or thread-safe).

If you say anything, let’s say for example “vector” -> then the interviewer will ask you about Vector. (Understand the psychology)

4. Describe Collection Tree or Collection interface.

By Ervinn at en.wikibooks [CC BY-SA 3.0 ], from Wikimedia Commons

The list of core collection interfaces are: just mention the important ones

Important: Collection, Set, Queue, List, Map

Other interfaces also on the list: SortedSet, SortedMap, Deque, ListIterator, etc.

Collection interface and classes | Image from Edureka

The above image is quite easier to remember easily. Honestly, I recommend this image to everyone!

5. What is the difference between Map and Set?

Map object has unique keys each containing some value, while Set contains only unique values.

6. What is the difference between List and Set?

Set contains only unique elements while List can contain duplicate elements.

Set is unordered while the List is ordered. List maintains the order in which the objects are added.

7. How to reverse the List in Collections?

There is a built-in reverse method in the Collections class. reverse(List list) accepts the list as a parameter.

Collections.reverse(listobject);

8. What are the classes implementing Set and List interface?

Class implementing Set interface: HashSet, TreeSet

Class implementing List interface: ArrayList, Vector, LinkedList

9. What is the difference between Queue and Stack?

The Queue is a data structure that is based on FIFO ( first in first out ) property. An example of a Queue in the real-world is buying movie tickets in the multiplex or cinema theaters.

The Stack is a data structure that is based on LIFO (last in first out) property. An example of Stack in the real-world is the insertion or removal of CD from the CD case.

10. Which design pattern followed by Iterator?

It follows the iterator design pattern. An iterator design pattern provides us to navigate through the collection of objects by using a common interface without letting us know about the underlying implementation.

Enumeration is an example of an Iterator design pattern.

Bonus Que: Difference between String, String Buffer, String Builder

String, String Buffer, String Builder — java interview questions

11. Which methods you need to override to use any object as a key in HashMap?

To use any object as a key in HashMap, it needs to implement equals() and hashCode() method.

12. What is the difference between Iterator and Enumeration?

The main difference between Iterator and Enumeration is that Iterator has remove() method while Enumeration doesn’t.

Hence, using Iterator we can manipulate objects by adding and removing the objects from the collections. Enumeration behaves like a read-only interface as it can only traverse the objects and fetch it.

13. What is an iterator?

The Iterator is an interface. It is found in java.util package. It provides methods to iterate over any Collection.

14. How to convert the array of strings into the list?

Arrays class of java.util package contains the method asList() which accepts the array as a parameter. So, your code will be something like this snippet,

String[] wordArray = {“Abraaa” , “kaaa” , “Daabraaaa”};

List wordList = Arrays.asList(wordArray);

15. When to use interface and abstract class?

You can find the best answer here about when to use Interface or Abstract class.

You can check out Intermediate and Advance level questions here.

Java Collections - Advanced Questionnaire

Java Collections - Intermediate 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).

list
1

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.

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments

There are no comments for this story

Be the first to respond and start the conversation.

Sign in to comment

    Find us on social media

    Miscellaneous links

    • Explore
    • Contact
    • Privacy Policy
    • Terms of Use
    • Support

    © 2024 Creatd, Inc. All Rights Reserved.