I wonder if there is any performance differences in two below scenarios - peek() vs map() with return:
Set<Item> convertedItems = items
.stream()
.filter(item -> ItemType.POSTER.equals(item.getType()))
.peek(item -> item.setType(ItemType.LOGO))
.collect(toSet());
or
Set<Item> convertedItems = items
.stream()
.filter(item -> ItemType.POSTER.equals(item.getType()))
.map(item -> {
iitem.setType(ItemType.LOGO);
return item;
})
.collect(toSet());
I read several post on stackoverflow about setters in map() vs peek() and I found only one information about performance. It said that map() with return would be worse but without explaining why: How to call setter in chain of Stream