I need to check if the Id variable of a class is null or not. If it is null I must insert it in one list and if it is not null I must insert it in another list. I'm doing it this way:
I didn't want two streams, I would like to do only one and Strem and filter, can you help me?
Emails with null ids will persist in the database.
List<Email> emails = payment.getUser().getEmails();
if (!emails.isEmpty()){
List<Email> create = emails.stream().filter(email -> email.getId() == null).collect(Collectors.toList());
List<Email> existingEmails = emails.stream().filter(email -> email.getId() != null).collect(Collectors.toList());
}