Modify property value of the objects in list using Java 8 streams

前端 未结 5 1772
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 04:26

I have a list of Fruit objects in ArrayList and I want to modify fruitName to its plural name.

Refer the example:

@Data
@Al         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 04:54

    You can use just forEach. No stream at all:

    fruits.forEach(fruit -> fruit.setName(fruit.getName() + "s"));
    

提交回复
热议问题