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);
solved Filtering on unrelated variable in java streams