Here's my code as per now.
List<Cat> cats = petStore.getCatsForSale();
if (!cats.empty)
logger.info("Processing for cats: " + cats.size());
for (Cat cat : cats) {
cat.giveFood();
}
My colleague writes realy nice code using the Java stream API. I tried to rewrite it as one streaming statement, but I got stuck.
petStore.getCatsForSale().stream.forEach(cat -> cat.giveFood)
.countTheCats().thenDo(logger.info("Total number of cats: " + x)); // Incorrect... is this possible?
How can I do this? Ideally I want a single streaming statement...