Reading file and ignoring its contents

In this post under Apache Commons IO, I will show with example how to read a file and ignore the contents that we have read. In Apache Commons IO framework, we have static utility class “IOUtils”, which has a method “consume” which reads a file and ignore the contents that it has read. Below is…… Continue reading Reading file and ignoring its contents

Mapping two enums with different constant name

In this post under MapStruct I will show with example how to map two enums having different constant name. For our example lets say you have to map below enum Day package package12; public enum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY; } to below enum Week package package12; public enum Week {…… Continue reading Mapping two enums with different constant name

Making Java objects available during sqel expression evaluation

In this post under Spring SpEL, I will explain with example how to make java objects available to SpElExpression during its evaluation. For our example we will use the below pojo class Employee package spel.package20; public class Employee { private int id; private String name; private int salary; public Employee(int id, String name, int salary)…… Continue reading Making Java objects available during sqel expression evaluation

Mapping two enums with same constant name

In this post under MapStruct, I will show with example how to map between two enums both having same constant name. For our example, I will use the below two enums ProcessStatus package package11; public enum ProcessStatus { RUNNING, PAUSE, CANCELLED, SHUTDOWN; } DisplayStatus package package11; public enum DisplayStatus { RUNNING, PAUSE, CANCELLED, SHUTDOWN; }…… Continue reading Mapping two enums with same constant name

Populating the entire array with different elements

In this post under Java Collections, I will show with example an api provided in “Arrays” class that will populate an array with different element. We are talking about “Arrays” class static method “setAll”. It takes two arguments1) the array to be populated2) a function that will generate the elements that are to be inserted…… Continue reading Populating the entire array with different elements

Populating the entire array with same element

In this post under Java Collections, I will show with example an api provided in “Arrays” class that will populate any array with a particular element. We are talking about “Arrays” class static method “fill”. It takes two arguments1) the array to be populated2) the element to be fill int array For our example I…… Continue reading Populating the entire array with same element

SpelExpressionParser example

In all my previous post under Spring SpEL, I was letting Spring framework to evaluate the SpEL expression when creating the Spring application context. In addition to that we can manually evaluate a SpEL expression using SpelExpressionParser class. This class is provided by Spring framework and below example shows how to use it. Main class…… Continue reading SpelExpressionParser example

Arrays toString method

In this post under Java Collections, I will show with example how to convert an array into its string representation. In Java, any object when converted to its string representation, it calls the object’s “toString” method. The default behavior of “toString” method is to print the below information getClass().getName() + ‘@’ + Integer.toHexString(hashCode()) In case…… Continue reading Arrays toString method

Ternary operator in SpEL

In this post under Spring SpEL, I will show with example how to use ternary operator in SpEL. Below is the main class for your reference. Main class 1 package spel.package18; 2 3 import org.springframework.beans.factory.annotation.Value; 4 import org.springframework.context.ApplicationContext; 5 import org.springframework.context.annotation.AnnotationConfigApplicationContext; 6 import org.springframework.context.annotation.Bean; 7 import org.springframework.context.annotation.Configuration; 8 9 import java.util.Arrays; 10 import java.util.List; 11…… Continue reading Ternary operator in SpEL