Supun Wijerathne :
Imagine I have a list of elements.
List<Session> sessions;
Imagine this is populated with some elements.
And I have another list which is a sub list of the above list.
List<Session> successSessions;
As name suggests, the latter is the set of success sessions out of the first list. Therefore the remaining list is the list of failedSessions
.
What is an effective way to get failedSessions
populated using the whole list of sessions and successSessions
?
Thank You in advance.!!!
Naman :
You can do it using removeAll
as:
List<Session> failedSessions = new ArrayList<>(sessions); // initialise with 'sessions'
failedSessions.removeAll(successSessions);