Preventing a property from being marshalled to xml file

By default all properties of an instance are marshalled as elements in an xml file. As shown below.. Marshalling an Country insance with below class structure Country package package2; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Country { private int id; private String name; private int population; public int getId() { return id; } public void setId(int… Continue reading Preventing a property from being marshalled to xml file

Consumer Functional Interface Example

Java 8 added a new functional interface named “Consumer”. The purpose of this interface is to consume/process the information received, it doesn’t return anything. I will be explaining using the below example. In the example I have list of employees whom I want to terminate. I will pass the list of employees to an implementation… Continue reading Consumer Functional Interface Example

BiPredicate Simple Example

This post explains BiPredicate functional interface. BiPredicate is similar to Predicate functional interface except BiPredicate takes two arguments instead of one. In the below example we will filter list of Person entities based on first and last name. The predicate class name will be “NamePredicate”. NamePredicate package Function; import java.util.function.BiPredicate; public class NamePredicate implements BiPredicate… Continue reading BiPredicate Simple Example

Different ways to convert list to array

This post explains two ways through which we can convert a list to array. First approach is simply calling toArrayList on list instance. This method returns an Object array, When converting to array it doesn’t consider the data type of the entries in the list. Below is the code snippet list.toArray(); The second approach involves… Continue reading Different ways to convert list to array