Reading through this article, I can filter the collection like this:
Set<Status> statusClone = cloner.deepClone(statusList).stream().filter(s -> !(s instanceof FileMetadata)).collect(Collectors.toSet());
However, I will also need to set the properties simultaneously filtering them. After filtering them, I currently iterate through each one and then set properties:
for (Iterator<Status> iterator = statusClone.iterator(); iterator.hasNext();)
{
Status s = iterator.next();
// if (s instanceof FileMetadata)
// {
// iterator.remove();
// continue;
// }
s.setStatus(JobStatus.UNINITIATED);
s.setLastAccessedTime(0);
s.setOffSet(null);
s.setStreamNo(null);
}
statusList.addAll(statusClone);
Is this possible in Java8 without using foreach?
EDIT: From the comments, I agree that I can clone inside the filter. Thanks.