If you are open to using a third-party library, Eclipse Collections has specialized methods called sumBy that work well with lambdas.
If you use the MutableList from Eclipse Collections for the moveTracking list, the code looks like this:
MutableList<MoveTrack> moveTracking = Lists.mutable.empty(); ObjectDoubleMap<String> doubleMap = moveTracking.sumByDouble(MoveTrack::getMonthName, MoveTrack::getMovementAmount);
It is up to you to determine where and how you want to implement getMonthName() . You will notice that sumByDouble returns an ObjectDoubleMap . This means that you can use double for your movementAmount , and it will not fit during the summation.
If you want to keep your List<MoveTrack> type as it is at present, you can use the ListAdapter or Iterate to accomplish the same thing.
List<MoveTrack> list = ...; ObjectDoubleMap<String> doubleMap = Iterate.sumByDouble(list, MoveTrack::getMonthName, MoveTrack::getMovementAmount);
Note: I am a committer for Eclipse collections
source share