Java Programming
ArrayList to HashMap in java
ArrayList is a dynamic array.As we discussed in pervious post, ArrayList is slower than arrays but there is no restriction on size.Based on requirement, we can keep growing the elements in the list. HasMap is used for storing Key/Value as elements.But order of the elements is the same as we store the elements in it.Since … Read more
MapStruct – Easy & fast way to map Java beans
import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; class Employee { Employee(int id, String name, String email) { this.id = id; this.employeeName = name; this.email = email; } private int id; private String employeeName; private String email; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getEmployeeName() { … Read more
What is Predicate Functional Interface in Java 8
Predicate in Java 8 The Predicate is one of the Functional Interfaces type introduced in Java 8. Generally predicate means a statement that determines if a value could be true or false. So predicate is used to test a condition which will return a boolean value. Syntax: @FunctionalInterface public interface Predicate { boolean test(T t); … Read more
Java 8 BiFunction Examples
Java 8 BiFunction BiFunction is a functional interface introduced in Java 8.BiFunction interface’s method takes two parameter (T and U ) and returns one parameter(R) as output. Syntax: @FunctionalInterface public interface BiFunction { R apply(T t, U u); } T: Type of the first argument to the function U: Type of the second argument to … Read more
Functional Interfaces in Java
Functional Interfaces in Java In Java, being an object oriented programming language, everything revolves around Objects and classes.If we want to write a simple one statement for displaying a message using System.out.print then also we need to write a class to have such method.Means we can’t write any function/method without writing a class in java. … Read more
Exception Handling in Java(With Examples)
Exception Handling Exception is an abnormal condition in a java program which disrupts the normal flow the program.Few examples are bad coding, wrong input data, network connectivity issue etc. Technically exception is and object that contains the exceptional details like error message and line at which issue has happened etc.When such a situation arise in … Read more
Autoboxing & Unboxing of Wrapper classes
Wrapper class, Autoboxing and Unboxing Wrapper class: In java if we want to work on various data types ,we have primitives(int, char, long etc) types available but if you want to work only with objects then wrapper classes can be helpful. Wrapper class is a class in java which is a wrapper around primitive data … Read more
Set in Java
Set in Java Set interface is an unordered collection of elements but you can’t store duplicate values in Set.It does not maintain the insertion order.To use the set, we can use 4 classes. 1)HashSet 2)LinkedHashSet 3)EnumSet 4)TreeSet We can create the implementation object for any of above classes: HashSet: If we don’t care about the … Read more
Java Arrays
Java Arrays An array is a data structure which will store only homogeneous elements.That means all the elements stored in an array would be of same data type. For example if we create an array of string then all the elements which can be stored would be of type String only.Other data types like int,long … Read more