I am trying to convert this piece of code to Java 8 stream:
if(list!=null && list.size()>0){
Actor actor = null;
for(Actor actor:list){
I think that using forEach in this case would be working quite nice for you? Example:
list.stream().forEach(actor -> {
log.info(String.format("Actor being read {%s}", actor));
String actorCode = actor.getCode();
areaDAO.getArea(actorCode).stream().findFirst().ifPresent(area -> {
actor.setArea(area);
log.info(String.format("Area {%s} is fetched for actor {%s}", area, actorCode));
});
getContext().setReadCount(1);
})
You may want to throw in Objects.isNull() as well in some cases - e.g for that getCode part - as well as Optional.ofNullable?