Java Collections

Java 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.

Related Tags

Tutorials

Java Collections

How to Create Immutable Map in Java?

Learn to create an immutable or unmodifiable Map using the factory methods added in Java 9 and other versions (Java 8 to Java 21) with examples.

Java Enumeration, Iterator, ListIterator and Spliterator

In Java, all types of enumerations and iterators (such as Iterator, ListIterator, SplitIterator) are simply navigational cursors and the main purpose of these cursors is to iterate over the elements of the collection. Each cursor has its own features, advantages and disadvantages. In this article, we will walk through these …

Java ArrayList Length and Size

Java ArrayList does not publicly expose the length of the backing array, and only the count of the stored elements can be retrieved using its size() method.

Java Map computeIfAbsent()

The Map.computeIfAbsent() method computes the mapped value for a key using a mapping function if the specified key does not exist in the Map or is mapped to a null value. It has been added as the default method in the Map interface in Java 8. 1. When to Use the computeIfAbsent() …

Java ConcurrentSkipListMap

Learn the Java ConcurrentSkipListMap and the major differences between ConcurrentSkipListMap and other Map implementations.

Create and Initialize List with Values in One Line

A Java List can be initialized in various ways. However, initializing a list with multiple elements can be a tedious task. This tutorial will discuss different techniques to initialize a list in one line to make your work easy and reduce boilerplate code. Method List Attributes Java Version List list …

Java ArrayDeque with Examples

Learn about Java ArrayDeque and its features with practical examples. Learn to use it as Stack and Queue, and the difference from LinkedList.

Java SynchronousQueue with Example

Java SynchronousQueue is a specific type of BlockingQueue with no internal capacity and is primarily used in exchanging data between two threads.

How to Flatten a Nested List in Java

Flattening a nested list may seem hard at the beginning, but it’s not. It can be easily done using only plain Java, streams, or external libraries.

Convert List to Map in Java

Learn to convert a List to a Map in Java using Streams, Commons collections, and Guava including Multimap class for duplicate list items.

Inverting a Map In Java

This Java tutorial will teach us how to invert a given Map using different techniques. We will learn to invert Maps with unique values and create Multimap when there are duplicate values. 1. What is an Inverted Map? An inverted Map <V, K> is an instance of the original Map<K, …

Intoduction to Java Collections

A collection is a group of objects. Java Collections framework consists of classes and interfaces to work with lists, sets, maps and queues.

Java Collection Tutorials

This Java guide will take us through Java Collections framework. We will understand the core concepts and performing the basic operations.

Java List

Lists are the core building blocks of the Collections framework. These tutorials will teach us the basics of different List classes in Java.

Java Map

Maps in Java are the core building blocks of the Collections framework. These tutorials will teach the basics of working with different maps.

Get SubMap From Map In Java

A submap is a portion or part of a map between the keys of a specific range. Learn how to get submap from map in Java with different ways.

Java EnumMap with Examples

Learn to create and work with the Java EnumMap in detail, difference between EnumMap and HashMap and the practical usecases for the same.

Java Nested Map with Examples

A nested Map is Map inside another Map. Learn to create a nested HashMap and add, remove and iterate over the elements with examples.

Java TreeMap vs HashMap

Learn the differences between TreeMap and HashMap in Java as both implements the Map interface but differ in functionality and performance.

Guide to Java IdentityHashMap

IdentityHashMap implements the Map interface and has almost the same features as HashMap. It uses reference equality on key search operations.

Guide to Java ConcurrentMap

ConcurrentMap is an interface in Java Collections and used to create a thread-safe Maps. It stores the key-value pairs in a synchronized way.

Guide to Java WeakHashMap

Learn about the Java WeakHashMap, strong & weak references with examples. Also, learn the differences between WeakHashMap and HashMap.

Java CopyOnWriteArraySet class

CopyOnWriteArraySet is a thread-safe Set in Java. It ensures safe concurrent access by creating a new copy of the internal array for each modification.

Java CopyOnWriteArrayList class

Java CopyOnWriteArrayList is a thread-safe variant of ArrayList in which all mutative operations (add, set, and so on) are implemented by making a fresh copy of the underlying array. It’s immutable snapshot style iterator method uses a reference to the state of the array at the point that the iterator …

Java TransferQueue Vs. LinkedTransferQueue

In Java, the TransferQueue interface is a concurrent BlockingQueue implementation with support to support “synchronous message passing” between producers and consumers. The key feature of TransferQueue is the transfer() method that blocks until the message is handed off to a consumer. 1. TransferQueue Interface The TransferQueue is an interface in …

Java ArrayBlockingQueue class

ArrayBlockingQueue class is Java concurrent and bounded blocking queue implementation backed by an array. It orders elements FIFO (first-in-first-out). The head of the ArrayBlockingQueue is that element that has been on the queue the longest time. The tail of the ArrayBlockingQueue is that element that has been on the queue …

Java PriorityBlockingQueue class

Java PriorityBlockingQueue class is concurrent blocking queue data structure implementation in which objects are processed based on their priority. The “blocking” part of the name is added to imply the thread will block waiting until there’s an item available on the queue.

Java Spliterator (with Examples)

Unlike traditional iterators, Spliterator is designed with parallelism in mind and mainly helps in parallel processing when the collection or stream has a large number of elements.

Java ListIterator (with Examples)

The Java ListIterator interface is a bidirectional iterator that iterates over the elements in both forward and backward directions.

Guide to Java Iterator

Java Iterator interface is used to iterate over the elements of a Collection (List, Set or Map). The Iterator helps in retrieving the elements from the specified collection one by one and optionally performs operations over each element. Java Iterator was first introduced in Java 1.2 as a replacement of Enumerations. …

Java Comparator Interface

Java Comparator interface used to sort a array or list of objects based on custom order. Custom ordering of elements is imposed by implementing Comparator.compare() method in the objects.

Java Comparable Interface

Java Comparable interface is part of Collection Framework. Learn the purpose of Comparable interface and use it in different scenarios. 1. Comparable Interface 1.1. Why Implement Comparable? In Java, if we want to sort a List of elements then we can Collections.sort() method. It sorts the list items according to …

Java LinkedList class

Java LinkedList class is doubly-linked list implementation of the List and Deque interfaces. It implements all optional list operations, and permits all elements (including null). Table of Contents 1. LinkedList Hierarchy 2. LinkedList Features 3. LinkedList Constructors 4. LinkedList Methods 5. LinkedList Example 6. LinkedList Usecases 7. LinkedList Performance 8. …

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.