I have 2 List list:
//Dynamic lists - sent in request
List<String> types = {"VCX", "ATCH", "Warrnty"};
//hardcoded eligble list in code
List<String> eligibleTypes = {"VCX", "ATCH", "Warrnty"};
Now I want to return true if any of the entries in types list is present in hardcoded eligibleTypes list? How can I write a clean code using Java streams?
boolean isAnyChildEligible = types.stream()
.anyMatch(type -> isEligibleProgram(type, eligibleTypes));
private boolean isEligibleProgram(String type, List<String> eligibleTypes) {
if(!CollectionUtils.isEmpty(eligibleTypes) && eligibleTypes.contains(type)) {
return true;
}
return false;
}
Any better way of doing the above? Using some other method? Will the above even work?
CollectionUtilsyou use here!CollectionUtils.isEmpty(eligibleTypes)?