我需要检查类的Id变量是否为null。如果为null,则必须将其插入一个列表中;如果不为null,则必须将其插入另一列表中。我这样做是这样的:
我不希望有两个流,我只想做一个,然后使用Strem和过滤器,您能帮我吗?
具有空ID的电子邮件将保留在数据库中。
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());
}
Run Code Online (Sandbox Code Playgroud)