Maybe what you actually want is to use a Predicate
?
Predicate<Integer> crazyFunction = x -> false;
for (Integer thisInteger : listOfIntegers) {
crazyFunction = crazyFunction.or(Predicate.isEqual(thisInteger));
}
// Is a given integer one of our integers?
boolean isGoodInteger = crazyFunction.apply(42);
2
solved How can I change one function value in a boolean-valued java Function?