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 […]
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 […]
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 […]
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 […]
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 […]
In this short post, let’s learn how to display characters from a to z using loop 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 […]
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 […]
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 […]
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 […]
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 […]
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 […]
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 […]
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 […]
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 […]
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. […]
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 […]
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 […]
Java does not have a direct method to sort a string. You can do it using Stream API provided in Java 8.
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 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, […]
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 […]
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 […]
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 […]
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 […]
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 […]
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.
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 […]