Top 22 Collection Interview Questions and Answers in Java

preview_player
Показать описание
The collections framework was designed to meet several goals, such as −

The framework had to be high-performance. The implementations for the fundamental collections (dynamic arrays, linked lists, trees, and hashtables) were to be highly efficient.

The framework had to allow different types of collections to work in a similar manner and with a high degree of interoperability.

The framework had to extend and/or adapt a collection easily.

Towards this end, the entire collections framework is designed around a set of standard interfaces. Several standard implementations such as LinkedList, HashSet, and TreeSet, of these interfaces are provided that you may use as-is and you may also implement your own collection, if you choose.

A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain the following −

Interfaces − These are abstract data types that represent collections. Interfaces allow collections to be manipulated independently of the details of their representation. In object-oriented languages, interfaces generally form a hierarchy.

Implementations, i.e., Classes − These are the concrete implementations of the collection interfaces. In essence, they are reusable data structures.

Algorithms − These are the methods that perform useful computations, such as searching and sorting, on objects that implement collection interfaces. The algorithms are said to be polymorphic: that is, the same method can be used on many different implementations of the appropriate collection interface.

In addition to collections, the framework defines several map interfaces and classes. Maps store key/value pairs. Although maps are not collections in the proper use of the term, but they are fully integrated with collections.

The Collection Interfaces

The collections framework defines several interfaces. This section provides an overview of each interface −

Sr.No.Interface & Description1The Collection Interface

This enables you to work with groups of objects; it is at the top of the collections hierarchy.

2The List Interface

This extends Collection and an instance of List stores an ordered collection of elements.

3The Set

This extends Collection to handle sets, which must contain unique elements.

4The SortedSet

This extends Set to handle sorted sets.

5The Map

This maps unique keys to values.

6The Map.Entry

This describes an element (a key/value pair) in a map. This is an inner class of Map.

7The SortedMap

This extends Map so that the keys are maintained in an ascending order.

8The Enumeration

This is legacy interface defines the methods by which you can enumerate (obtain one at a time) the elements in a collection of objects. This legacy interface has been superceded by Iterator.

The Collection Classes

Java provides a set of standard collection classes that implement Collection interfaces. Some of the classes provide full implementations that can be used as-is and others are abstract class, providing skeletal implementations that are used as starting points for creating concrete collections.

The standard collection classes are summarized in the following table −

Sr.No.Class & Description1

AbstractCollection

Implements most of the Collection interface.

2

AbstractList

Extends AbstractCollection and implements most of the List interface.

3

AbstractSequentialList

Extends AbstractList for use by a collection that uses sequential rather than random access of its elements.

4LinkedList

Implements a linked list by extending AbstractSequentialList.

5ArrayList

Implements a dynamic array by extending AbstractList.

6

AbstractSet

Extends AbstractCollection and implements most of the Set interface.

7HashSet

Extends AbstractSet for use with a hash table.

8LinkedHashSet

Extends HashSet to allow insertion-order iterations.

9TreeSet

Implements a set stored in a tree. Extends AbstractSet.

10

AbstractMap

Implements most of the Map interface.

11HashMap

Extends AbstractMap to use a hash table.

12TreeMap

Extends AbstractMap to use a tree.

13WeakHashMap

Extends AbstractMap to use a hash table with weak keys.

14LinkedHashMap

Extends HashMap to allow insertion-order iterations.

15IdentityHashMap

Extends AbstractMap and uses reference equality when comparing documents.

The AbstractCollection, AbstractSet, AbstractList, AbstractSequentialList and AbstractMap classes provide skeletal implementations of the core collection interfaces, to minimize the effort required to implement them.

Sr.No.Class & Description1Vector

This implements a dynamic array. It is similar to ArrayList, but with some differences.

2Stack

Stack is a subclass of Vector that implements a standard last-in, first-out stack.

3Dictionary

Dictionary is an abstract class that represents a key/value storage repository and operates m
Рекомендации по теме
Комментарии
Автор

Well done.
This is the best information i found on youtube for java collections interview questions.

hughjackson
Автор

It is very helpful for my interview. Thanks bro

neelurunarayanaswamy
Автор

My java technical interview on tomorrow.. And am very happy to see this viedo.. It's very informative... Super😍❤❤

vineethaabcd
Автор

awesome collection of collection based interview questions

sunilbharitkar
Автор

One of the best interview questions for collection, it is very easy to understand the questions and answers for preparing interviews, it is very helpful for me. Thank you dear for your efforts. 😍👍

emnbick
Автор

great collection of java interview questions and answers.

sabkuchhlearn
Автор

Thank you very much for this wonderful video on collection in java . It helps me a lot 💖

NaveenSharma-liwu
Автор

Recap all things and also learnt some new things

PraveenKumar-ujih
Автор

Property file not only recompilation purpuse the main pros and cons to achieving the losslely couple for ur components but unfortunately we can't fully losslely couple of ur components we only achieved partially partially in a framework level development environment time as well production environment 👍

pratapjavasingh
Автор

Awesome work!!
Please also do video for other concepts ... OOPS

Sudheerkreddy
Автор

Lagta h ek hi difference hai List aur set m.

someshdhawale