In this post under Java, I will show with example how to check whether two arrays are equal or not. The class Arrays under java.util package has “equals” static method which takes two arrays as arguments and compare their contents to check whether they are same. Below is the code showing an example Main 1…… Continue reading Comparing two arrays for equality
Category: Core
Getting a list of ClassPath scanned by a Java Program
In this post under Java, I will post the code which will list all the paths a Java Program uses to search for linked jars and resources. Below is the main method Main class 1 package classloader; 2 3 import java.net.URL; 4 import java.net.URLClassLoader; 5 6 public class ClassPath { 7 public static void main(String[]…… Continue reading Getting a list of ClassPath scanned by a Java Program
BiConsumer’s andThen Example
In this post under Java, we will explain with an example the andThen method under BiConsumer functional interface. BiConsumer’s andThen method is used to chain one BiConsumer interface implementation with one or more BiConsumer interface implementations. Lets consider an example. I have a list of TCS employees with the class structure as shown below TCSEmployee…… Continue reading BiConsumer’s andThen Example
BiFunction’s andThen Example
In this post under Java, we will explain with an example the andThen method under BiFunction functional interface. BiFunction’s andThen method is used to chain a BiFunction interface implementation with one or more Function interface implementations. Lets consider an example. I have a list of employess with their salary and percent of bonus to apply…… Continue reading BiFunction’s andThen Example
BiConsumer Example
In this post, I will show how to use BiConsumer functional interface with an example. BiConsumer functional interface is similar to Consumer functional interface. It takes an input, processes it and doesn’t return anything. The difference lies in the number of inputs taken by the BiConsumer functional interface. Consumer functional interface takes one input whereas…… Continue reading BiConsumer Example
Private Interface Methods
From Java 9 onwards, we can declare private methods in interface. In this post I will show with an example of how to do it. Private methods in interface are useful if you have logic shared by more than one default interface methods. We can put the shared logic in the private method. Below is…… Continue reading Private Interface Methods
BiFunction Example
In this post, I will show how to use BiFunction functional interface with an example. BiFunction functional interface is similar to Function functional interface. It takes an input and produces an output. The difference lies in the number of inputs taken by the BiFunction functional interface. Function functional interface takes one input and produced one…… Continue reading BiFunction Example
Combining two or more Function functional interface
In this post, I will explain how to combine Function functional interfaces. They are two ways in which we can combine Function functional interface and it is achieved using two methods in Function interface as mentioned below 1) default Function andThen(Function after) 2) default Function compose(Function before) Both the methods accept an implementation of Function…… Continue reading Combining two or more Function functional interface
Function functional interface
In this post, with an example I will show how to use Function functional interface. Function interface is a functional interface that takes an input and produces an output. This is achieved by its “apply” method. Below is an example Main Code 1 package function; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 import java.util.function.Function;…… Continue reading Function functional interface
Sorting a section of an array
In this post I will explain how to sort a section of an array. The java Arrays class provides a static method named “sort” which takes the below three arguments 1) the array 2) fromIndex 3) toIndex This method sorts a section of the array. The section to be sorted is indicated by fromIndex (position…… Continue reading Sorting a section of an array