Core Java

HashSet In Java

Introduction: HashSet in Java implements Set interface i.e. it doesn’t allow duplicates. It is internally backed by a HashMap which works on the principle of hashing.  We can store a null value in a HashSet. Its default capacity is 16 with a load factor of 0.75, where:

A Java HashSet is non-synchronized. Also, there’s no guarantee […]

Be the First to comment. Read More
Core Java

Sorting a HashMap In Java

Introduction: In this tutorial, we’ll learn how to sort a Java HashMap. We can sort a HashMap either by keys or by values. We’ll discuss both of these strategies. Sorting a Java HashMap: To follow along with the rest of the article, let’s first construct a HashMap:

where Student is a POJO with id and […]

Be the First to comment. Read More
Core Java

Java Convert a List to Array And Vice-Versa

Introduction: In this article, we’ll quickly learn how to convert a Java List (say an ArrayList) to an array and vice-versa. If you wish to learn more about an ArrayList in general, feel free to read our article on Java ArrayLists. Meanwhile, let’s get going! Convert Java List to Array: Converting a Java List to an array is […]

Be the First to comment. Read More
Core Java

Check If Two Lists Are Equal In Java

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 […]

Be the First to comment. Read More
Core Java

CopyOnWriteArrayList In Java

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 […]

Be the First to comment. Read More
Core Java

Java – Remove all nulls from a List

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: […]

Be the First to comment. Read More
Core Java

LinkedList In Java

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 […]

Be the First to comment. Read More
Core Java

Java UUID

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:

And has 36 characters that include four hyphens ‘-‘. java.util.UUID class in Java represents an immutable UUID. We can use UUID class for […]

Be the First to comment. Read More
Spring

Spring MVC Annotations

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:

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 used Spring […]

3 comments Read More
Core Java

Java Queue Interface

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 […]

One comment Read More