Cleanup resource automatically with Project Lombok

When we use a resource like InputStream, OutputStream in Java, we should remember to close that resource after using. Before Java 7, we can close a resource in a finally block as below:

Since Java 7, we can use the try with resource to… Read More

Logging with Project Lombok

Normally, when we use a Logging framework like Log4J, Logback or Simple Logging Facade for Java (SLF4J) for these Logging frameworks in a class, we need declare for example as below:

But with Project Lombok, we don’t need to do that. When using Project… Read More

Builder Pattern with Project Lombok

Normally, when we need to create an object with a lot of its information, we can use the Builder Pattern for that purpose. For example, I have a Student class as below:

To build this object with all information using the Builder Pattern, we… Read More

Getter, Setter and Constructors with Project Lombok

In this tutorial, I will show you how we can use Project Lombok to generate Getter, Setter methods or the constructors in a Java object automatically. OK, first of all, we need to create an example Maven project. with Project Lombok dependency as below:

Read More

Using flatMap() method of Stream object in Java

When working with Stream in Java, sometime we can have a Stream with datatype of a List, Set or Array of object. For example:

Here, we have List of List of String object and when convert into Stream object, we have Stream of List… Read More

Sort a Map using Stream and Collectors in Java

In this tutorial, I will show you how to order elements in a Map object using the Stream object and the Collectors object in Java by key and by value. For example, we have a Map object like this:

Prior to Java 8, to… Read More