Posts

How to transform Array of objects to another Array of objects using Java 8 streams?

Image
Hello everyone, here we will show you how to convert an Array of objects to another Array of objects using Java streams map(). The ‘map’ method maps each element to its corresponding result.  Java Stream API The Java Stream API provides a functional approach to processing collections of objects. The Stream in Java can be defined as a sequence of elements from a source Collection or Array. Most of the stream operations return a Stream. This helps create a chain of stream operations(stream pipe-lining). The streams also support the aggregate or terminal operations on the elements. for example, finding the minimum or maximum element or finding average etc...Stream operations can either be executed sequentially or parallel. when performed parallelly, it is called a parallel stream. Stream map() Method The Java 8 Stream map() is an intermediate operation.It converts Stream<obj1> to Stream<obj2>. For each object of type obj1, a new object of type obj2 is created and put in the ne

Java Stream API - How to convert List of objects to another List of objects using Java streams?

Image
In this section, we will show you how to convert a List of objects to another List of objects in Java using the Java streams map(). The ‘map’ method maps each element to its corresponding result. Java Stream API   The Java Stream API provides a functional programming approach over the object oriented capabilities of Java. It is used for processing collections of objects. The Stream in Java can be defined as a sequence of elements from a source List, Set or Array. Most of the stream operations return a Stream. This avails engender a chain of stream operations(stream pipe-lining). The streams withal support the aggregate or terminal operations on the elements. for example, finding the sum or maximum element or finding the average etc...Stream operations can either be executed sequentially or parallel. when performed parallelly, it is called a parallel stream.   Stream map() Method   The Java 8 Stream map() is an intermediate operation. It converts Stream<obj1> to Stream<obj2>

Spring Data JDBC, PostgreSQL, CRUD Example

Image
  Hello everyone, In this article, we will learn how to develop a  REST-style web service with Spring Boot, Spring Data JDBC, and PostgreSQL Database. GitHub repository link is provided at the end of this tutorial. You can download the source code. What's new in this example?  From Java 14 onwards,  the record  is a special type of class declaration aimed at reducing the boilerplate code. For more info  click here From Java 10 onwards,  the var  keyword allows local variable type inference, which means the type for the local variable will be inferred by the compiler, so we don't need to declare that. For more info  click here Technologies used :  Spring Boot 2.6.3 Spring  Data JDBC  Java 17  PostgreSQL Maven 3+  These are APIs that Spring backend App will export:   GET all User's        :     /api/v1/users             : get  GET User by ID     :     /api/v1/users/{id}       : get CREATE User        :     /api/v1/users             : post UPDATE User        :     /api/v1/user