I have the following code in Java 7:
List<Integer> idMappers= new ArrayList<>();
//getting information from a Map<String, List<String>>
List<String> ids= idDataStore.lookupId(id);
for (int i = 0; i < ids.size(); i++) {
//getting information from a Map<String, List<Integer>>
List<Integer> mappers= idDataStore.lookupMappers(ids.get(i));
if (mappers!= null) {
for (int j = 0; j < x.size(); j++) {
idMappers.add(mappers.get(j));
}
}
}
I'm trying to change this to Streams
List<Integer> idMappers= new ArrayList<>();
idDataStore.lookupIdMappings(id).forEach(id-> {
idDataStore.lookupSegments(id).forEach(mapper->{
idSegments.add(segment);
});
});
My problem is idDataStore.lookupSegments(id)
can sometimes throw null so my stream is breaking. How Can I do a null check in Stream?