Converting Collection to unmodifiable List

In this post under Java, I will show with example how to convert a collection to unmodifiable list. To convert a collection to an immutable List, we take help of “List” interface static method “copyOf”. Below is the complete code for your reference. Main class 1 package core.collection; 2 3 import java.util.HashSet; 4 import java.util.List;…… Continue reading Converting Collection to unmodifiable List

Mapping from multiple objects to one destination object

In this post under MapStruct, I will explain with example how to map attributes from multiple objects to attributes of one single destination object. For our example I will two source class as shown below Person package package4; public class Person { private int id; private String name; private int age; private char sex; //Removed…… Continue reading Mapping from multiple objects to one destination object

Spring @Value annotation

In this post under Spring Core, I will show with example how to use “@Value” annotation. In previous post I showed how to access system properties, environment properties, custom properties using “Environment” interface. In all these case we had to explicitly retrieve the value as shown below and are not injected into the bean automatically…… Continue reading Spring @Value annotation

Iterating a list in both direction

In this post under Java, I will show with example how to iterate a list in both directions. For iterating in both direction, we will take the help of “ListIterator” class. We get an instance of “ListIterator” by calling “listIterator” method on a list. Below is the code snippet, where “integerList” is a list of…… Continue reading Iterating a list in both direction

Sorting a list

In this post under Java, I will show with example how to sort a list. Below is the complete main class 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 SortingList { 8 public static void main(String []args) { 9 List<Integer> integerList…… Continue reading Sorting a list

assertThrows vs assertThrowsExactly example

In this post under JUnit, I will show with example the purpose of “assertThrowsExactly” method and how it is different with “assertThrows” method. I have explained with example, the purpose of “assertThrows” static method in previous posts. For recap, “assertThrows” method asserts that the test method throws the expected exception. If the test method doesn’t…… Continue reading assertThrows vs assertThrowsExactly example

beforeAll and afterAll annotation

In this post under JUnit, I will explain with example the purpose of “beforeAll” and “afterAll” annotations. In the previous post under JUnit, I covered about “beforeEach” and “afterEach” annotation. Similarly to “beforeEach” and “afterEach”, “beforeAll” and “afterAll” is applied to methods. But methods annotated with “beforeEach” and “afterEach” annotations are executed before and after…… Continue reading beforeAll and afterAll annotation