How to sum up the individual fields of the object list and return the results as a single object
问题 I have a method which is calculating nutrients for a list of object which we are receiving from API request call. The method looks like: public Nutrients nutrientsCalculator(DailyMeals dailyMeals) { String foodNamesForRequest = prepareFoodNamesForRequest(dailyMeals); HttpEntity<NutrientsBodyForRequest> requestBody = prepareRequestForAPICall(foodNamesForRequest); ResponseEntity<List<FoodNutritional>> response = //create request here if (nonNull(response.getBody())) { double totalFat = response