Is there any collection in java that won't add null object? Given a list of item, query DB for those items, when the result returned from DB, i'll add the item to result list if it does exist in DB, if it doesn't DB return null, then I'll discard it.
I have following code does this:
reqIds.forEach(
reqId -> {
columnValueMap.clear();
columnValueMap.put("request_id", reqId);
EventAudit auditRecord =
pollDatabaseFindByIdAndKey(
EventAudit.class, columnValueMap);
if (auditRecord != null) {
auditMap.put(auditRecord.getRequestId(), auditRecord);
}
});
i know i can use Java stream filter to filter out null but just wonder if there is any smart collection that will reject null object automatically so i don't need to do extra Null checking