I have a list of errorCodes which I want to check whether or not they contain error codes in a separate array. If the error codes exist in list errorCode then I want to filter those out.
This is what I have so far
int[] ignoredErrorCodes = {400, 500};
List<Error> errorCodes = errorsList.stream()
.filter(error -> error.getErrorCode() != ignoredErrorCodes[0])
.collect(Collectors.toList());
how can I check against all values in the array ignoredErrorCodes instead of just one, using streams?
It would be better to store the ignoreds codes in a Set
for faster lookup:
Set<Integer> ignored = Set.of(400,500);
List<Error> errorCodes = errorsList.stream()
.filter(error -> !ignored.contains(error.getErrorCode()))
.collect(Collectors.toList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With