I am new to Java 8 and i have a response object which has a list of detail object and the detail object contains a list of reason object where the reason object has a reason code. I am trying to iterate to the reason object from the response object and search if there is any reason code equal to a given key. Could you please help in how to do that in java 8, with minimum complexity. Below is sample way in java 7 not the best approach thou.
if(response != null && CollectionsUtil.isNotEmpty(response.getDetails())) {
List<Detail> details = response.getDetails();
for(Detail det : details) {
if(CollectionsUtil.isNotEmpty(det.getReasons())) {
for(Reason reason: det.getReasons()) {
if(StringUtils.equalsIgnoreCase("ABC", reason.getReasonCode())) {
///////////call an external method
}
}
}
}
}
CollectionUtil.isNotEmpty()might perform a null check.