Posts

Showing posts with the label Java

Java, Spring Boot Mini Project - Library Management System - Download

Image
Hello everyone, Here, we provide a Library Management System mini-project for beginners, it's free for download. Maybe you can build more on top of this project and create your own product, that's all about you. The source code download link is provided at the end of this post. 1. Benefit of this project You could cover the following technologies and features by learning and debugging this mini project. Java 17 Java Stream Java Lamda Expressions Java Records Functional programming Object-oriented programming var Keyword in Java Generics in Java Java Switch Spring boot 2.6.4 Spring Security Thymeleaf template engine OpenCSV Spring Data JPA Server Side Pagination H2 Database  Bootstrap HTML CSS and more... 2. Objective Of Spring Boot On Library Management System The main objective of this project is to manage the details of the books, author, category, and publisher. Only Admin/Librarian will manage all these activities. Also, they can export the data in CSV file format. 3. Funct

Java 8 Stream - Remove duplicates from a list of objects based on a property

Hello everyone, here we will show you how to remove duplicates from a list of objects based on a single property.  In this example, we are getting the stream from the list and putting it in the TreeSet from which we provide a custom comparator that compares id, email, or salary uniquely. Here we are going to remove duplicates based on the, id(Long) property of the user email(String) property of the user salary(Double) property of the user User.java public class User { private Long id; private String name; private String email; private String phone; private Double salary; public Long getId() { return id; } public void setId( Long id) { this .id = id; } public String getName() { return name; } public void setName( String name) { this .name = name; } public String getEmail() { return email; } public void setEmail( String email) { this .email = email

How to iterate over Array in Java?Six (6) ways to loop over an Array in Java

Iteration is a technique used to sequence through a block of code perpetually until a concrete condition either subsist or no longer subsists. Iterations are a very prevalent approach utilized with loops. In this article, we will show you  Six (6) ways to loop over an Array in Java. 1.  Using  Simple For loop  2.  Using  Enhanced For loop  3.  Using  While loop 4.  Using  Do - while loop 5. Using Stream.of() and forEach 6. Using Arrays.stream() and forEach Example 1: Using Simple For loop     // create an array String [] users = { "alpha" , "beta" , "giga" , "gama" , "tesla" }; // Simple For loop for ( int i = 0 ; i < users.length; i++) { System.out.println(users[i]); } Example 2:  Using Enhanced For loop  The enhanced for loop is introduced since J2SE 5.0. It is used to traverse the array or collection elements.  // create an array String [] users = { "alpha

How to convert Set of objects to another Set of objects using Java streams?

Image
Hello everyone, here we will show you how to convert a Set to another Set in Java 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 new Stream.