有沒有更好的方法來做到這一點 - 它是這樣一個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'。這就是'!'操作符的用途。 –