Posts

Spring Boot + Angular: File Upload & Download Example

Image
Hello everyone, today we will learn how to upload and download file with Spring Boot and Angular. You can download the source code from our GitHub repository. Backend Project Directory: Frontend Project Directory: We will build two projects:  1. Backend:  springboot-fileupload-filedownload 2. Frontend: angular-file-upload Project 1: springboot-file-upload-download pom.xml <?xml version = "1.0" encoding = "UTF-8" ?> <project xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns = "http://maven.apache.org/POM/4.0.0" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" > <modelVersion> 4.0.0 </modelVersion> <parent> <groupId> org.springframework.boot </groupId> <artifactId> spring-boot-starter-parent </artifactId> <version> 2.7.0 </version> <!-- lookup parent fro

Java - Swap Two Numbers

In this post, you will learn how to code Java Program to Swap Two Numbers using 2 different methods. 1. Using third variable 2. Without using third variable Java Program to Swap Two Numbers Method 1 : using third variable import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; public class Main { public static void main (String []args) throws IOException { InputStreamReader isr = new InputStreamReader(System. in ) ; BufferedReader br = new BufferedReader(isr) ; System. out .println( "Enter first number: " ) ; int firstNumber = Integer. parseInt (br.readLine()) ; System. out .println( "Enter second number: " ) ; int secondNumber = Integer. parseInt (br.readLine()) ; //Before Swapping two numbers System. out .println( "Before Swapping :" ) ; System. out .println( "First number is " +firstNumber) ; System. out .println( "S

Java 8 Streams - Count Frequency Of Words In a List

Image
Example 1   import java.util.Arrays ; import java.util.List ; import java.util.Map ; import java.util.function.Function ; import java.util.stream.Collectors ; public class Main { public static void main ( String [] args) { List < String > words = Arrays . asList ( "cat" , "rat" , "bat" , "cow" , "cat" , "bat" ); // For Long values Map < String , Long > result = words .stream() .collect( Collectors . groupingBy ( Function . identity (), Collectors . counting ())); System . out .println( result ); } } The List interface in Java provides a way to store the ordered collection. It is a child interface of Collection. It is an ordered collection of objects in which duplicate values can be stored. The asList () method of java.util.Arrays class is used to return a fixed-size list backed by the specified array. This metho

Java 8 Streams - Program To Break A List Into Batches Of Given Size

Image
In this post, we will show how to break a list into batches of a given size. Example 1: Convert List of Characters into batches of a given size import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; public class Main { public static void main( String [] args) { List < Character > list = Arrays .asList( 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' ); int chunkSize = 3 ; AtomicInteger ai = new AtomicInteger(); Collection < List < Character >> chunkedOrders = list.stream() .collect(Collectors.groupingBy(item -> ai .getAndIncrement() / chunkSize)) .values(); chun