Intermediate Level (1-3 yrs): Java Collections Interview Questions and Answers List wordList = Arrays.asList(wordArray) Q15 How to convert the array of strings into the list?Īrrays class of java.util package contains the method asList() which accepts the array as a parameter. reverse(List list) accepts the list as a parameter. There is a built-in reverse method in the Collections class. Q14 How to reverse the List in Collections? An example of Stack in the real-world is the insertion or removal of CD from the CD case. The Stack is a data structure that is based on LIFO (last in first out) property. An example of a Queue in the real-world is buying movie tickets in the multiplex or cinema theaters. The Queue is a data structure that is based on FIFO ( first in first out ) property. Q13 What is the difference between Queue and Stack? To use any object as a key in HashMap, it needs to implement equals() and hashCode() method. Q12 Which methods you need to override to use any object as a key in HashMap? 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.Įnumeration is an example of an Iterator design pattern. Q11 Which design pattern followed by Iterator? Enumeration behaves like a read-only interface as it can only traverse the objects and fetch it. Hence, using Iterator we can manipulate objects by adding and removing the objects from the collections. The main difference between Iterator and Enumeration is that Iterator has remove() method while Enumeration doesn't. Q10 What is the difference between Iterator and Enumeration? It provides methods to iterate over any Collection. 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. Q3 What is the difference between Collection and Collections? So if the question includes collection hierarchy, then you should answer the question as Collection interface (which is found in java.util package). For the Iterable interface Oracle doc, the iterable interface is not mentioned as a part of the Java Collections framework. It is clearly mentioned in Oracle Collection docs, that Collection interface is a member of the Java Collections framework. But you should reply iterable interface present in java.lang package not in java.util package. So iterable should be the root interface. The Collection interface extends the Iterable interface. The root interface in the collection hierarchy is the Collection interface. Q2 What is the root interface in the collection hierarchy? Increases the chances of reusability of software Q1 What is Collection? What is a Collections Framework? What are the benefits of the Java Collections Framework?Ĭollection : A collection (also called a container) is an object that groups multiple elements into a single unit.Ĭollections Framework : Collections framework provides a unified architecture for manipulating and representing collections.Ģ. The interviewer may choose to ask any questions.īeginner Level (0-1 yr): Java Collections Interview Questions and Answers Intermediate level (1, 2, 3 years experienced Java Developers)Īdvanced level(3+ Experienced) java collections interview questions and answers We will divide this post into three categories (Updated for 2023) :īeginner level (0-1 year experience (Freshers)), Today, we will learn about the top 50 java collections interview questions and answers. I also shared the tricky coding interview questions in our previous posts. We have already shared the most frequently asked java interview questions for experienced candidates.
0 Comments
Leave a Reply. |