[Solved] Filtering on unrelated variable in java streams

[ad_1]

A one possible solution is to define a custom predicate like this:

Predicate<Item> myPredicate = item -> randomVar == 42;

Then you can use the predicate in your stream:

items
    .stream()
    .filter(myPredicate)
    .forEach(System.out::println);

[ad_2]

solved Filtering on unrelated variable in java streams