有没有更好的方法来做到这一点 - 它是这样一个boilderplate代码。 我使用Java 8,我会用流做到这一点 - 但我需要一些帮助做到这一点。我尝试过... removeIf()但它没有工作。Java不包含列表中的对象列表b
final List<CalendarEventUserConnection> calendarEventUserConnectionsToDelete = new ArrayList<>();
for (final CalendarEventUserConnection existingCalendarEventUserConnection : existingCalendarEventUserConnections) {
boolean contains = false;
for (final CalendarEventUserConnection newCalendarEventUserConnection : calendarEventUserConnections) {
if (newCalendarEventUserConnection.getId() != null
&& newCalendarEventUserConnection.getId().equals(existingCalendarEventUserConnection.getId())) {
contains = true;
}
}
if (contains == false) {
calendarEventUserConnectionsToDelete.add(existingCalendarEventUserConnection);
}
}
有没有更好的方式来提出这个问题?它几乎不包含任何信息。 – Adam
这样做 - 什么是“这个”?如果你无法解释,我们肯定不会是 –
是的。不要使用20个以上的字符变量名称。不要使用'== false'。这就是'!'操作符的用途。 –