In this post under Java Core, I will explain with example the pupose of Collections’ “indexOfSubList” method. Lets say they are two lists list1 and list2. “indexOfSubList” will search in list1 for position from where the elements of “list2” are repeated in “list1”. Once the position is found it is returned as index. In other…… Continue reading Collections indexOfSubList method
Skipping mapping of particular attribute
In this post under MapStruct, I will show with example how to configure MapStruct to skip particular attribute mapping from source to destination. For our example I will use the below pojo classes as shown below Student package package3; public class Student { private int id; private String name; private String className; public int getId()…… Continue reading Skipping mapping of particular attribute
AllowedRegexRule example
In this post under Passay, I will explain with example the purpose of “AllowedRegexRule” class. When validating password, we mainly check whether the password follows a particular pattern. If the password follows the pattern it is valid or else invalid. We use regular expressions, to create that pattern. “AllowedRegexRule” class will do the job of…… Continue reading AllowedRegexRule example
Collections replaceAll method
In this post under Java Collections, I will explain with example the purpose of Collections “replaceAll” method. This method replaces all occurrences of a particular element with its replacements. This method can be used only with “List” data structure. Below is the main class showing an example Main class 1 package core.collection; 2 3 import…… Continue reading Collections replaceAll method
Java Comparable interface
In this post under Java Collections, I will explain with example the purpose of “Comparable” interface. Before we understand “Comparable” interface we need to understand the difference between “ordered” and “sorted” collections. In Ordered collections, elements are placed in a collection according to insertion order or according to some order and the order is not…… Continue reading Java Comparable interface
Sealed Classes and interfaces
In this post under Java, I will explain with example the purpose of Sealed classes and interfaces. Sealed classes are the classes that doesn’t allow themselves to be inherited by any unspecified classes. Only those classes which are permitted by sealed classes, are allowed to inherit the sealed class. Lets take an example. A “Shape”…… Continue reading Sealed Classes and interfaces
Object Mapping between classes with different attributes
In the previous post under MapStruct I showed an example of how to use MapStruct framework for object mapping. I assumed that attribute names in source class and destination class are same. What if they are not. In this post, I will show with an example how to configure MapStruct to map between source and…… Continue reading Object Mapping between classes with different attributes
Simple Object Mapping Example
In this post under MapStruct, I will show with simple example how to map one object attribute values to another object attributes. For our example I will have two classes as shown below Student package package1; public class Student { private int id; private String name; private String className; /*getter and setter methods for each…… Continue reading Simple Object Mapping Example
Populating collection with multiple elements in one single method call
In this post under Java, I will show with example the purpose of static “addAll” method in “Collections” class. The “addAll” method populates a collection with the given list of elements. This method takes two arguments1) the collection that it has to fill or populate2) variable length arument that will contain the elements that has…… Continue reading Populating collection with multiple elements in one single method call
Collections frequency method
In this post under Java, I will show with example the purpose of “frequency” static method in “Collections” class. The “frequency” method returns the number of times an element is repeated in a collection. This method takes two argument1) the collection it has to search2) the element for which it has to return the frequency.…… Continue reading Collections frequency method