eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

Partner – LambdaTest – NPI EA (cat= Testing)
announcement - icon

Distributed systems often come with complex challenges such as service-to-service communication, state management, asynchronous messaging, security, and more.

Dapr (Distributed Application Runtime) provides a set of APIs and building blocks to address these challenges, abstracting away infrastructure so we can focus on business logic.

In this tutorial, we'll focus on Dapr's pub/sub API for message brokering. Using its Spring Boot integration, we'll simplify the creation of a loosely coupled, portable, and easily testable pub/sub messaging system:

>> Flexible Pub/Sub Messaging With Spring Boot and Dapr

1. Introduction

In this tutorial, we’re going to discuss how to choose the proper collection interface and class in the Java library. We skip legacy collections, such as Vector, Stack, and Hashtable in our discussion as we need to avoid using them in favor of the new collections. Concurrent collections deserve a separate topic, so we don’t discuss them either.

2. Collection Interfaces in the Java Library

It’s very useful to know the organization of the collection interfaces and classes in the Java library before trying to use them efficiently. The Collection interface is the root of all the collection interfaces. List, Set, and Queue interfaces extend the Collection.

Maps in the Java library are not treated as regular collections, so the Map interface doesn’t extend Collection. Here’s the diagram for interface relationships in the Java library:

Collection

Any concrete collection implementation (collection class) is derived from one of the collection interfaces. The semantics of collection classes are defined by their interfaces, as concrete collections provide specific implementations for operations that their parent interfaces define. Consequently, we need to choose the proper collection interface before selecting the suitable collection class.

3. Choose the Right Collection Interface

Choosing the right collection interface is somewhat straightforward. Indeed, the diagram below shows a logical interface selection flow:

Interface Selection Diagram

To summarize, we use lists when the insertion order of elements matters and there are duplicate elements. Sets are used when elements are treated as a set of objects, there are no duplicates, and the insertion order doesn’t matter.

Queues are used when LIFO, FIFO, or removal by priority semantics is required, and finally, maps are used when the association of keys and values is needed.

4. Choose the Right Collection Implementation

Below we can find the comparison tables of collection classes separated by the interfaces they implement. The comparisons are made based on common operations and their performance. Specifically, the performance of operations is estimated using Big-O notation. A more practical guide to operations’ duration in Java collections can be found in the benchmark of collection operations.

4.1. Lists

Let’s start with a list comparison table. Common operations for lists are adding and removing elements, accessing an element by index, traversal of the elements, and finding an element:

Lists Comparison Table Add/remove element in the beginning Add/remove element in the middle Add/remove element in the end Get i-th element (random access) Find element Traversal order
ArrayList O(n) O(n) O(1) O(1) O(n), O(log(n)) if sorted as inserted
LinkedList O(1) O(1) O(1) O(n) O(n) as inserted

As we can see, ArrayList is good at adding and removing elements in the end, as well as having random access to elements. Conversely, it’s bad at adding and removing elements at arbitrary positions. Meanwhile, LinkedList is good at adding and removing elements at any position. However, it doesn’t support true O(1) random access. So, regarding lists, the default choice is ArrayList until we need fast element addition and removal at any position.

4.2. Sets

For sets, we’re interested in adding and removing elements, traversal of elements, and finding an element:

Sets Comparison Table Add element Remove element Find element Traversal order
HashSet amortized O(1) amortized O(1) O(1) random, scattered by the hash function
LinkedHashSet amortized O(1) amortized O(1) O(1) as inserted
TreeSet O(log(n)) O(log(n)) O(log(n)) sorted, according to elements comparison criterion
EnumSet O(1) O(1) O(1) according to the definition order of the enum values

As we can see, the default choice is the HashSet collection, as it’s very fast for all the operations it supports. Furthermore, if also the insertion order of elements matters, we go with LinkedHashSet. Basically, it’s an extension of HashSet, which keeps track of elements’ insertion order by using a linked list structure internally.

If the elements need to be sorted and the sorted order needs to be preserved while adding and removing elements, then we go with TreeSet.

If the elements of the set are just enumeration values of a single enum type, then the wisest choice is EnumSet.

4.3. Queues

Queues can be divided into two groups:

  1. LinkedList, ArrayDequeQueue interface implementations can act as the stack, queue, and dequeue data structures. Generally, ArrayDeque is faster than LinkedList. Hence it’s the default choice
  2. PriorityQueue – Queue interface implementation backed by the binary heap data structure. Used for fast (O(1)) element retrieval, which has the highest priority. Addition and removal work in O(log(n)) time

4.4. Maps

Similarly to sets, we consider the operations of adding and removing elements, traversal of elements, and finding an element for maps:

Maps Comparison Table Add element Remove element Find element Traversal order
HashMap amortized O(1) amortized O(1) O(1) random, scattered by the hash function
LinkedHashMap amortized O(1) amortized O(1) O(1) as inserted
TreeMap O(log(n)) O(log(n)) O(log(n)) sorted, according to elements comparison criterion
EnumMap O(1) O(1) O(1) according to the definition order of the enum values

The selection logic for maps is similar to the selection logic for sets: we use HashMap by default, LinkedHashMap if additionally, insertion order is important, TreeMap for sorting, and EnumMap when keys belong to values of a specific enum type.

Lastly, there are two implementations of the Map interface, which have very specific applications: IdentityHashMap, and WeakHashMap.

5. Concrete Collection Selection Diagram

We can extend the diagram for choosing the proper collection interface for selecting concrete collection implementations:

Concrete Collection Selection Diagram

6. Conclusion

In this article, we went through collection interfaces and collection classes in the Java library. Moreover, we proposed methods for selecting the correct interface and implementation.

Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

eBook Jackson – NPI EA – 3 (cat = Jackson)