Tony Neves
Tony Neves

Reputation: 7

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);
    }
}

Upvotes: 0

Views: 796

Answers (1)

Alberto
Alberto

Reputation: 12939

It would be:

quoteOptions
  .stream()
  .filter(el -> el.getFet() > 0)
  .foreach(el -> el.setApplyFet(true))

Upvotes: 2

Related Questions