For example there is a class similar to this:
class NameBudget {
String name;
Integer budget;
}
I am getting the list of budgets using the streams:
listOfNameBudgets.stream().map(NameBudget::getBudget()).collect(Collectors.toList())
How can I get the cumulative budget for each entry of the list using streams?
I am avoiding to first create a list of budget and then do the cumulative. It should be possible to do it while creating the list from an object.
If the list was:
[ {
"name":"A"
"budget":1
},
{
"name":"B"
"budget":2
},{
"name":"C"
"budget":5
}
]
the output list would be [1, 3, 8]