In the previous post under Java Record, I mentioned how the compiler creates a long (canonical) constructor automatically. In this post, I will explain how to create a custom canonical constructor. Now why we need to provide a custom canonical constructor when it is already provided by compiler. The canonical constructor created by compiler will…… Continue reading Custom Canonical constructor in Record
Tag: Java
Collections checkedCollection example
In this post under Java, I will explain with example the purpose of Collections “checkedCollection” method. From Java 5 onwards, we started using Generics to ensure compile time type safety. As a result of which we were unable to add element of one data type to collections of elements of another data type. At compile…… Continue reading Collections checkedCollection example
Collections indexOfSubList method
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
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
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
Renaming an ldap entry
In this post under Java LDAP, I will show with example how to rename an ldap entry. To rename an ldap entry, Java LDAP api provides “rename” method which takes two arguments1) the current name/fully qualified dn2) the new name/fully qualified dn Below is the complete main code for your reference Main class 1 package…… Continue reading Renaming an ldap entry
Removing an attribute of an ldap entry
In this post under Java LDAP, I will show with example two approaches to remove a existing attribute from an existing ldap entry. For our example I will remove an attribute by name “telephoneNumber” from an ldap entry identified by dn. Below is the complete main class for your reference Main class 1 package package7;…… Continue reading Removing an attribute of an ldap entry
Shuffling elements of a list
In this post under Java Collections, I will show with example how to randomly shuffle elements of a list. Below is the complete code for your reference. Main class 1 package core.collection; 2 3 import java.util.ArrayList; 4 import java.util.Collections; 5 import java.util.List; 6 7 public class ShuffleListDemo { 8 public static void main(String[] args) {…… Continue reading Shuffling elements of a list