Skip to content

Tag: java-8

Create list of objects from another list by using java8 stream

I have a list student list A and I have student list B. Student objects contains some fields like that : no,age,city,birth_date,salary My list A contains these objects My list B contains these objects What i want to do is extract student objects that ListA have but listB not and ListA and ListB have(as no,age,city) but salary is different.Also I

How to Iterate list of list of Java Objects using Java 8

How to iterate and get through list of list of objects using Java 8 Also need to get the count of distinct customerIds CustomerEditVO and CustomerIssues are POJOs Post Request body —> Answer I have created all the given POJO’s and created the objects and list for your query.And also overrides the toString() method in order to clearly show the

How to round off to the closest 5 minute interval if it is 1 or 2 minutes ahead or behind?

I want to round off an Instant / LocalDateTime to its closest 5 minutes interval in Java. Examples: Suppose the time is: 2021-02-08T19:02:49.594 Expected result: 2021-02-08T19:00:00.000 Suppose the time is: 2021-02-08T19:03:49.594 Expected result: 2021-02-08T19:05:00.000 Similarly, if the time is: 2021-02-08T19:56:49.594 Expected result: 2021-02-08T19:55:00.000 Similarly, if the time is: 2021-02-08T19:58:49.594 Expected result: 2021-02-08T20:00:00.000 But if the time is 2021-02-08T19:55:00.000 or 2021-02-08T19:05:00.000

How to iterate over MultipartFile array using Java lambda and streams

Below is my code to upload some file attachments to external storage. I would like to know if there is a way to avoid for loop in the below method to iterate over the MultipartFile[] array so that everything will be done using the java streams and lambda functions. Would like to have any better way to achieve the below

How to convert an array of map into a map in JAVA8?

Right now I have How to use JAVA8 stream to convert it into Update: Sorry I was being unclear. The map_array contains two maps, and each map has two entries with the first one being key as “k”, value as “k1” and second entry being key as “v” and value as “v1”. Now I’m trying to merge them into one