想象一下,我们有 3 个对象的列表,其值为分钟字段:5,5,7,8
int sumOfFields = found.stream()
.filter(abc -> minutesLessThan5(abc.getMinutes())))
.mapToInt(abc::getMinutes)
.sum();
// will return 10
但是我怎样才能改变我的输出,例如代替 getMinutes 我想返回我自己的值,例如 40
int sumOfFields = found.stream()
.filter(abc -> minutesLessThan5(abc.getMinutes())))
.mapToInt(abc ->abc.getMinutes() = 40) //this is pseudo code what I try to achive
.sum();
// output should be 80.
HUX布斯
相关分类