'How to set an object attribute's value based on another attributes value?
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);
}
}
Solution 1:[1]
It would be:
quoteOptions
.stream()
.filter(el -> el.getFet() > 0)
.foreach(el -> el.setApplyFet(true))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alberto Sinigaglia |
