Hello, I have a dtos list that has a flag. I need to filter them and return.
The logic is that if there are two elements in the list and one of them is deleted, I retrieve the unused one, but if there is only one element and is deleted, I return it.
So basically the order is not deleted> deleted> new item.
List<Item> existingItems = service.getItems();
existingItems.stream().filter(e -> !e.getIsDeleted()).findAny().orElse(new Item());
How can I change the pipeline Streamto implement the desired logic?
source
share