![]() Vector is synchronized while ArrayList is not. It is one of the frequently asked collection interview questions, the main differences are Q16 What is the difference between ArrayList and Vector? Intermediate Level (1-3 yrs): Java Collections Interview Questions and Answers ![]() String wordArray = List wordList = Arrays. 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. ![]() Q8 What are the classes implementing List and Set interface?Ĭlass implementing List interface : ArrayList, Vector, LinkedListĬlass implementing Set interface : HashSet, TreeSet Map object has unique keys each containing some value, while Set contains only unique values. Q7 What is the difference between Map and Set? List maintains the order in which the objects are added. Set is unordered while the List is ordered. Set contains only unique elements while List can contain duplicate elements. Q6 What is the difference between List and Set? Other interfaces also on the list : SortedSet, SortedMap, Deque, ListIterator, etc. Important : Collection, Set, Queue, List, Map The list of core collection interfaces are : just mention the important ones Stack, Properties, Vector, and Hashtable can be used in a multi-threaded environment because they are synchronized classes (or thread-safe). Q4 Which collection classes are synchronized or thread-safe? 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 :ī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. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |