Reputation: 7
What would be the equivalent lambda expression for streaming through a list of objects. Then checking an objects attribute for a value and setting another attribute in the same object based on that value. Example:
List<OptionOverrideChangeOrderModel> quoteOptions =
Collections.singletonList(quoteOption);
for (OptionOverrideChangeOrderModel option : quoteOptions) {
if (option.getFet() > 0) {
option.setApplyFet(true);
}
}
Upvotes: 0
Views: 796
Reputation: 12939
It would be:
quoteOptions
.stream()
.filter(el -> el.getFet() > 0)
.foreach(el -> el.setApplyFet(true))
Upvotes: 2