Browse Source

143 of 151

Nick Satinover 5 years ago
parent
commit
d3288fb8e8
1 changed files with 6 additions and 2 deletions
  1. 6
    2
      src/main/java/rocks/zipcode/quiz5/collections/WordCounter.java

+ 6
- 2
src/main/java/rocks/zipcode/quiz5/collections/WordCounter.java View File

@@ -5,11 +5,15 @@ import java.util.Map;
5 5
 
6 6
 public class WordCounter {
7 7
     Map<String, Integer> map = new HashMap<>();
8
-    Integer counter = 0;
9 8
 
10 9
     public WordCounter(String... strings) {
11 10
         for (String s: strings) {
12
-            map.put(s, ++counter);
11
+            if (!map.containsKey(s)){
12
+                map.put(s, 1);
13
+            }
14
+            else {
15
+                map.put(s, map.get(s) + 1);
16
+            }
13 17
         }
14 18
     }
15 19