Java 8: iterate over Map of List of Objects

In this example I am going to show you how to iterate over map of list of objects. Let’s say you have keys as strings and values as list of objects in a HashMap. Now you want to iterate list of objects and want make one attribute of the object as keys and other attribute(s) as values and want to…

Collect and Convert Objects using Lambda Expression in Java 8 or Later Version

Introduction In this tutorial, I will show you how you are going to collect and convert objects using lambda expression in Java 8 stream API. I will collect objects and map to another custom objects using Java 8 stream API with the help of Lambda Expression. Suppose you have entity classes generated from your database tables and after fetching data…

Java 8 Stream Filter Example

Java 8 Filter This tutorial will show you how to use Java 8 stream API‘s filter() and map() methods. The filter() method in Java 8 or onward is used to produce a stream containing only a certain type of objects into the result output and map() method is used to transform a stream from one type to another type into…

Using Java Comparator in HashMap to Sort Elements

In this example I am going to show you an example on using Comparator in HashMap will show you how to use Comparator to sort values in HashMap. I will use custom object as a key in the HashMap. The object which is used as an object as a key in HashMap must override hashCode() and equals() methods.

Custom Object as a Key in HashMap

Java Custom Object In this Java HashMap example I am going to tell you how to use custom object as a key in HashMap. In custom object as a key in HashMap example, I will show you how to work with user defined objects as keys in Map. To use user defined objects as keys in Map you need to…

Add images to Word document using Apache POI

Introduction Add images to word document using apache poi will show you how to insert or add images into a Word document using Apache POI API. I will create here a Java based application to add images to word document using apache poi library. Using apache poi library is very easy to add images into word document. I am going…

Create Table in Word document using Apache POI

Introduction In this tutorial I will show you how to create Table in Word document using Apache POI API. Table is great representation when you have to display data in tabular format because table consists of rows and columns for displaying data uniformly. I will use both Apache POI 3.x and 4.x version to make the example works. I will…

Create Header and Footer in Word document using Apache POI

Introduction In this tutorial I will show you how to create Header and Footer in Word document using Apache POI API. Apache POI library is Java based API that makes our life easier to manipulate date on Microsoft office Documents. I will create here a Java application to create header and footer in word document using apache poi library. A…

Create a Word document using Apache POI

In this tutorial I will show you how to create a word document using apache poi or write to a word document using apache poi API. Microsoft word document is a great tool to document your stuff. This example is tested on both 3.15 and 4.1.1 versions of Apache POI library. I am also going to show you how to…

Fail Fast vs Fail Safe in Java

A system is called fail-fast if it stops immediately its execution when an error occurred. The system does not continue with the errors and these errors in the fail fast systems are immediately exposed. But, fail-safe system does the opposite thing. The fail-safe system does not stop its execution despite an error or a fault is occurred in the system….