简体   繁体   English

如何根据另一个属性值设置 object 属性值?

[英]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.通过对象列表流式传输的等效表达式 lambda 是什么。 Then checking an objects attribute for a value and setting another attribute in the same object based on that value.然后检查对象属性的值并根据该值在相同的 object 中设置另一个属性。 Example:例子:

List<OptionOverrideChangeOrderModel> quoteOptions = 
Collections.singletonList(quoteOption);
        
for (OptionOverrideChangeOrderModel option : quoteOptions) {
    if (option.getFet() > 0) {
        option.setApplyFet(true);
    }
}

It would be:这将是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过注释注入对象并在此对象上设置属性值 - How to inject an object via annotation and set an attribute value on this object 如果使用Java将属性具有相同的值,如何在Pojo列表中的属性值上附加++ 1 - how to append ++1 to an attribute value in a List of Pojo's if attributes has same value using java 如何根据 Spring Boot 中的活动配置文件设置注释属性值? - How to set annotation attribute value based on the active profile in Spring Boot? 在Java中创建Xpath以基于另一个属性值选择一个属性值 - Creating an Xpath in java to select an attribute value based on another attribute value Java:如何将默认值设置为注释,并将另一个注释作为其属性? - Java: how to set default value to annotation with another annotation as its attribute? 如何访问 Model 属性的值并设置为 ModelAndView - How to access Model Attribute's value and set to ModelAndView 如何将列表 object 的值设置到另一个列表 object 中? - How to set a value of List object into another List object? 根据属性检索节点元素的值 - Retrieve node element's value based on attribute 如何根据对象的属性对对象进行排序? - How To Sort Object based on Object's attribute? 如何根据另一个变量设置变量的值? - How do I set the value of a variable based on another variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM