Skip to content

Tag: java-stream

Converting to List result in Java

I have the following method: In this method, I pass a single menuUuid and then get combination of a single MenuPropertiesDTO and List<GroupExpDTO>. I want to pass a List<menuUuid> instead of a single menuUuid and then get the result according to the uuids in this list. However, I am confused if th…

Get updated object after mapping by lambda expression

I have a list of objects as following, I want to update one of these objects and I have the following implementation This returns an object which satisfied with the condition based on filter. Unfortunately this is an not-up-to-date object! How can I get the updated object after mapping? Answer This is because…

stream filter return null findFirst getting exception

The following will throw an exception, if the personList is empty or the filtered result is empty: I get the following error: How to solve the error? Actually, I just expect it should return one object or null. Answer get will throw an exception if called on an empty Optional. Instead, you could use orElse to…

Java code refactor with stream Collectors.groupingby()

I try to get a Map with Collectors.groupingBy() but I have no idea how to create… I have a List from jpa jquerydsl the data is like [memberId=1, departmentId=1] [memberId=1, departmentId=2] [memberId=2, departmentId=3] [memberId=3, departmentId=4] this is my Member class I want to parse tuple list to me…

Java 8 edit stream elements

I need to filter and modify the values of the filtered object. The logic that must be filtered is given below. I have tried it like this. But how can we set the value of isUpdated = true using java 8? Answer Base on the logic given, findFirst should be used as you stop after the first instance is found.