I have the following class:
public class Item { int id; String name; // few other fields, contructor, getters and setters }
I have
You can try use something like this:
ids.forEach(id -> list.stream() .filter(p -> p.getId() == id) .findFirst() .ifPresent(p -> { // do stuff here }); );
Optional here shows that your filter method can return a empty stream, so if you call findFirst it can find one or zero elements.