Introduction: Lists in Java are ordered by nature. So, two lists are considered to be equal if they contain the exact same elements in the same order. In this tutorial, we’ll see how to compare two Lists for equality in Java. We’ll also cover ways in which we can just compare the elements in two lists […]
Introduction: CopyOnWriteArrayList in Java is a thread-safe implementation of a List interface. It belongs to the java.util.concurrent package and is an enhanced version of ArrayList implementation. As the name suggests, CopyOnWriteArrayList creates a cloned internal copy of the underlying ArrayList for each add() or set() operations. Due to this additional overhead cost, we should ideally use a CopyOnWriteArrayList only when […]
Introduction: In this article, we’ll learn how to remove nulls from a Java List using plain-old Java, Java 8 lambda expression, and some third-party libraries. So, let’s get started! Removing nulls from a List In Java: Let’s explore different ways in which we can remove nulls from a Java List: 1. Java 7 or lower versions: […]
Introduction: A LinkedList is a linear data-structure composed of nodes. In a singly linked list, each node contains data and a reference. Here, the reference-part refers to the next node in the linked list. In a doubly linked list, on the other hand, we have data and references to both previous and next nodes. Java […]
Introduction: UUID (Universal Unique Identifier) represents a 128-bit long unique value. It’s also popularly known as GUID (Globally Unique Identifier). The standard representation of UUID is made up of hexadecimal digits: 533a4559-e55c-18b3-8456-555563322002 And has 36 characters that include four hyphens ‘-‘. java.util.UUID class in Java represents an immutable UUID. We can use UUID class for […]
Introduction: Spring 2.5 onwards, we can use annotations to mark our Spring components. One way of doing so is to use a <component-scan> tag in our appConfig.xml: <context:component-scan base-package="com.programmergirl" /> The Spring container will then recursively scan all components in the given package & its sub-packages. In this quick tutorial, we’ll discuss the most commonly […]
Introduction: A Queue is a FIFO (First In First Out) abstract data type (ADT). In other words, the elements are removed in the order in which they were inserted. The java.util.Queue is an interface in Java and extends from java.util.Collection. Some of the commonly used Queue implementation classes include a LinkedList, an ArrayDeque and a […]
Introduction: When running a Spring Boot application, we get a system exit code of 0, when everything goes fine. For any unhandled exceptions, the application returns with an exit code 1. It’s possible for us to return a custom exit code from our Spring Boot application. In this tutorial, we’ll learn to do so. Implementing […]
Introduction: In Spring MVC, we can set the status of the HttpResponse in several ways. In this tutorial, we’ll achieve it using the @ResponseStatus annotation. We can use @ResponseStatus to mark a method or an exception class with a status code and reason that should be returned. On invoking the marked handler method or when […]
Introduction: With Spring’s auto-scanning feature, it automatically detects various beans defined in our application. We usually annotate our beans using one of the available Spring annotations – @Component, @Repository, @Service, @Controller. On detecting the bean, Spring simply registers it into the ApplicationContext. In this quick tutorial, we’ll look at the difference between @Component, @Repository, and, […]