Nick Satinover 5 gadus atpakaļ
vecāks
revīzija
d3288fb8e8

+ 6
- 2
src/main/java/rocks/zipcode/quiz5/collections/WordCounter.java Parādīt failu

@@ -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