In this post under Java Collections, I will show with example how to convert an existing array to Stream. For this purpose, Java provides static method named “stream” in Arrays class. This method takes an array as an input and convert it into a stream. Below is the complete main code for your reference Main…… Continue reading Converting Array to Stream
Month: October 2024
Arrays copyOfRange method example
In this post under Java collections, I will show with example the purpose of “Arrays” class “copyOfRange” method. In the previous post under Java collections, I showed with example the purpose of “Arrays” class “copyOf” method. This method copies all the elements of input array to destination array. But what if we want to copy…… Continue reading Arrays copyOfRange method example
Generating random password using only user defined characters
In this post under Passay, I will show with example how to generate random password using user defined characters. To generate a random password, we need to come up with a list of “CharacterRule” instances. Each “CharacterRule” class take two data as constructor arguments as listed below1) instance of “CharacterData” interface2) min number of characters…… Continue reading Generating random password using only user defined characters
Mapping a map to a bean
In this post under MapStruct, I will show with example how to map values of Map to a bean. In our example we use map a Map to “StudentDTO” object. Below is the class structure of “StudentDTO” class. StudentDTO package package7; public class StudentDTO { private Integer id; private String name; private String className; //Removed…… Continue reading Mapping a map to a bean
Marshalling and Unmarshalling a generic object
In this post under Jackson –> JSON, I will explain with example how to marshal and unmarshal a generic object. Below is the complete main code for your reference Main class 1 package package14; 2 3 import com.fasterxml.jackson.core.type.TypeReference; 4 import com.fasterxml.jackson.databind.ObjectMapper; 5 6 import java.util.ArrayList; 7 import java.util.List; 8 9 public class Example14 { 10…… Continue reading Marshalling and Unmarshalling a generic object
Arrays.copyOf method
In this post under Java Collections, I will explain with example the purpose and how to use “Arrays” class public static method “copyOf”. Arrays.copyOf method takes a source array, creates a destination array, and copies the elements present in source array to destination array. Lets see an eample. Below is the main class Main class…… Continue reading Arrays.copyOf method
Mapping to existing bean instances
In this post under MapStruct, I will explain with example how to map attributes from source object to attributes of another existing object. In all my previous post under MapStruct, when mapping attributes from source object to destination object, the Mapper framework used to create the destination object before mapping. But there may be scenarios…… Continue reading Mapping to existing bean instances
Checking whether the password is already present in another source
In this post under Passay, I will show how to check whether the password is already used in another source. Below is the complete main class for your reference. Main class 1 package defaultPackage; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import org.passay.PasswordData; 7 import org.passay.PasswordData.SourceReference; 8 import org.passay.PasswordValidator; 9 import org.passay.RuleResult; 10…… Continue reading Checking whether the password is already present in another source
Accessing array in SpEL
In this post under Spring SpEL, I will show how to access array elements in SpEL expressions. For our example I will use the two beans. Below is the class structure of them Bean1 class package spel.package2; import org.springframework.stereotype.Component; @Component public class Bean1 { private int[] values = new int[] {1, 2, 3, 4}; public…… Continue reading Accessing array in SpEL
SpEL Simple example
In this post under Spring SpEL, I will give a simple example that shows how to access bean properties and use literal values in SpEL expressions. SpEL (Spring Expression Language) is an expression language that supports querying and manipulating objects at runtime. This expression language is written within “${ and “}” when used inside annotation…… Continue reading SpEL Simple example