I've just started using HashMaps in Java, and I was wondering if it's possible to sum up the object values in the HashMap.
I've already done this using an ArrayList like so:
private int totalWeight() {
int totalWeight = 0;
for(Item item : items){
totalWeight += item.getWeight();
}
return totalWeight;
}
I have different objects with the value weight, and I'm trying to return the total value of the weight as totalWeight, but can't seem to do so using HashMap.