


Collect Stream into Unmodifiable List, Set or Map with Java 8
Java 8 introduced a new Stream API that makes it easy to process collections of data. One of the most common tasks when working with streams is collecting the results […]

How to ignore a field while deserializing in Java if its type is not wrong?
public class UserAccount implements HasMoney { @JsonIgnore private BigDecimal money; // Other variable declarations, constructors @Override @JsonProperty public BigDecimal getMoney() { return money; } @JsonIgnore @Override public void setMoney(final BigDecimal money) { this.money = money; } // Other getters/setters }

Exception in thread “main” java.util.NoSuchElementException: No value present – How to fix?
NoSuchElementException would be thrown when you are trying to read a line/value that is not present in the source. One scenario would be when you try to read content from […]

Read nth line from file using Java 8 stream
Let’s take a file sample.txt which has the following contents. To read the 3rd line using Java 8 stream, we can use the following code snippet. If the line number […]

Join strings using StringJoiner in Java
StringJoiner is used to construct a sequence of characters separated by a delimiter and optionally starting with a supplied prefix and ending with a supplied suffix. Syntax Examples

Exception in thread “main” org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
EmptyResultDataAccessException is thrown when a result was expected to have at least one row (or element) but zero rows (or elements) were actually returned. This is a data issue. To […]

How to pass arguments into a Spring boot run?
To pass arguments when you are running a Spring Boot application you can simply assign your parameters to -Dspring-boot.run.arguments To retrieve these params and use them in your code, declare […]

Error: Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain
Caused by: java.lang.ClassNotFoundException: org.apache.maven.wrapper.MavenWrapperMain – How to fix?
When you are using maven as a build tool in your Spring Boot project you will get this error if there is no Maven wrapper found inside the root directory […]

Different ways of converting Array to ArrayList() in Java
In this post, we are going to see different ways of converting Array to ArrayList() in Java. Arrays.asList() method of java.util.Arrays class. Used to return a fixed-size list backed by […]

Array vs ArrayList in Java
In Java, we have two ways to create an array. Array – Simple fixed sized arrays. We cannot change its size. ArrayList – Is a class of Java Collections framework. It […]

Print characters from a to z using loop in Java
In this short post, let’s learn how to display characters from a to z using loop in Java.

Best way to handle nulls in Java
The Best Feeling at starting stage of my development is seeing the Output without ‘NullpointerException‘, but its very difficult. So handling null values is more important in Coding to get […]

Java String split() Method
In this post we will learn how we can convert a comma-separated String into the arrayList in Java. The split() method that splits the String into array of sub-string based […]

Parse String to JSON in Java
In this tutorial, we will learn how to parse string to JSON using different ways in Java.. JSON stands for Java Script Object Notation, most commonly format used to store […]

Iterate Map in Java 8 using Stream API
In this code snippet, you will learn how to iterate a map in Java 8 using Stream API. You can convert your entry set to a stream and then iterate […]

String Comparison in Java
In this article, We going to see the different ways to compare strings in Java. String is most commonly using datatype in java. And String comparison is very naturally used […]

Java String replace() and replaceAll() method
In this tutorial, we will see how the replace() and replaceAll() works and what’s the difference between these two methods. All of these Java String methods are mainly using for […]

How to efficiently iterate over Map in Java?
In this post, I am going to share my analysis over the iterating each entries of Map in Java. At sometime it is required to fetch all key-values pairs stored […]

Remove duplicate values from a List in Java
In this article, we will learn how to remove duplicate elements from a list in Java. Below are the some of the solutions. Plain Java We can use Set in […]

Remove cookies from a request while logging out – Java
Learn how to remove cookies from a request while logging out from a website/application. Session cookies store information related to the user and other data related to the user when […]

Validate US phone number and format with hyphens – Java
Here he would see on how to validate a US phone number on whether it is an integer, and on how to format it by adding hyphen without using loop. […]

Switch Expressions in Java – A quick introduction
In this post, we will quickly go through Switch Expressions which was introduced as a preview feature in JDK 12 and with yield keyword in JDK 13. The primary motive […]

Case conversion using Stream API in Java 8
There are no direct methods provided by the Java API to convert a string to different cases like Camel Case, Snake Case or Kebab Case. You can accomplish this using […]

Sort a string using Stream API in Java 8
Java does not have a direct method to sort a string. You can do it using Stream API provided in Java 8.

Shuffle/Randomize an array in JavaScript using Knuth Fisher-Yates shuffle algorithm
Knuth (Fisher-Yates) shuffle algorithm is an algorithm for randomly shuffling the elements of an array. The Knuth Fisher-Yates shuffle is used to randomly permute given input (list). The permutations generated […]

Text Blocks in Java 13
Text Blocks is one of the new features introduced in Java 13. Assigning a long string value to an Object has been a headache in Java. Thanks to text blocks, […]

Blocked by CORS policy error – How to fix?
Cross-Origin Resource Sharing (CORS) is a technique that makes use of additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources […]

Convert String to int in Java
The following list shows various ways to convert String to int (Integer) in Java. If your string contains only numbers and if you want to return the number it represents […]

Converting ArrayList to Array and Array to ArrayList in Java
This quick article is going to show how to convert between an Array and a ArrayList and vice versa. Convert ArrayList to Array The toArray() method in ArrayList (Resizable-array implementation of the List interface) returns an […]

Sort a HashMap in Java 8 by Key or Value
HashMap in Java does not maintain insertion order either by key or by order. Also it does not maintain any other order while adding entries to it. Using Java 8 […]

Check if BigDecimal variable is zero in Java (BigDecimal == 0)
From the Javadocs, A BigDecimal consists of an arbitrary precision integer unscaled value and a 32-bit integer scale. If zero or positive, the scale is the number of digits to the right of the decimal […]

How to increment date by one day in Java?
The following code snippet written in Java lets you increment date by any number of days. Just make sure you use the right date structure in Java.

Differences between java.util.Date and java.sql.Date in Java
Handling dates is tricky in Java just like handling JSON in Java. This confusion lets developers use libraries like Joda for clean handling of dates. For our references let’s call […]