You can pass the condition to your multiply(...) method and pass it to filter , as shown below.
multiplyNumbers(Arrays.asList(1, 2, 3, 4, 5), (x) -> x % 2 != 0).forEach(System.out::println); public static List<Integer> multiplyNumbers(List<Integer> input, Predicate<Integer> filterCondition){ return input.stream() .filter(filterCondition) .map(number -> number*2) .collect(Collectors.toList()); }
source share