How can I sum the values associated with a reoccurring key in a hashmap
问题 I want to add the values of the same keys in a hashmap. For example: ABC --> 123 DEF --> 456 ABC --> 123 XXX --> 111 XXX --> 222 should become: ABC --> 246 DEF --> 456 XXX --> 333 Here's the code I have so far: public class Reading { @SuppressWarnings("unchecked") public static void main(String[] args) throws IOException { //Create hashmap to store the the string and int in the excel sheet HashMap<String, Integer> hm = new HashMap<String, Integer>(); String key = null; int value = Integer.MIN