Q101.

What is hashing?

Q102.

What are HashMap contract rules?

Q103.

What is ConcurrentHashMap?

Q104.

What is the difference between StringBuilder and StringBuffer?

Q105.

What are the most common interfaces in Java collections?

The Java Collections Framework provides a powerful and unified architecture for representing and manipulating collections of objects. At its core, it relies on several key interfaces that define the types of collections and their fundamental behaviors, allowing for consistent use across various data structures and algorithms.

Overview of Java Collections Interfaces

Java's Collections Framework categorizes data structures through well-defined interfaces. These interfaces establish a contract for how a collection behaves, abstracting away the underlying implementation details. Understanding these interfaces is crucial for effectively choosing and using the right collection for a given task.

1. Collection Interface

This is the root interface in the collection hierarchy. It represents a group of objects, known as its elements. It defines the basic operations that all collections should support, such as adding and removing elements, checking if an element is present, determining the size, and iterating over elements. Most other collection interfaces extend Collection.

2. List Interface

A List is an ordered collection (also known as a sequence) that allows duplicate elements. It provides precise control over where each element is inserted and can access elements by their integer index (position). Common implementations include ArrayList (resizable array) and LinkedList (doubly-linked list).

3. Set Interface

A Set is a collection that contains no duplicate elements. It models the mathematical set abstraction. The order of elements is generally not guaranteed, though specific implementations like LinkedHashSet preserve insertion order. Common implementations are HashSet (uses a hash table) and TreeSet (uses a balanced binary search tree for sorted order).

4. Queue Interface

A Queue is a collection designed for holding elements prior to processing. Besides basic Collection operations, queues provide additional insertion, extraction, and inspection operations. They typically order elements in a FIFO (First-In, First-Out) manner. LinkedList (can act as a Queue) and PriorityQueue are common implementations.

5. Map Interface

While not strictly a 'Collection' (as it does not extend the Collection interface), Map is an integral part of the Java Collections Framework. It maps unique keys to values. A map cannot contain duplicate keys; each key can map to at most one value. Common implementations include HashMap (hash table-based), TreeMap (sorted by keys), and LinkedHashMap (preserves insertion order).