Seth 5 anni fa
parent
commit
89d9f3943e

+ 9
- 2
src/main/java/rocks/zipcode/quiz5/collections/WordCounter.java Vedi File

@@ -1,12 +1,19 @@
1 1
 package rocks.zipcode.quiz5.collections;
2 2
 
3
-import java.util.Map;
3
+import java.util.*;
4 4
 
5 5
 public class WordCounter {
6
+    private List<String> wordCounter;
6 7
     public WordCounter(String... strings) {
8
+        wordCounter = new ArrayList<>(Arrays.asList(strings));
7 9
     }
8 10
 
9 11
     public Map<String, Integer> getWordCountMap() {
10
-        return null;
12
+        Map<String, Integer> wordCountMap = new HashMap<>();
13
+        for(String each: wordCounter){
14
+            int count = wordCountMap.containsKey(each) ? wordCountMap.get(each) : 0;
15
+            wordCountMap.put(each, count +1);
16
+        }
17
+        return wordCountMap;
11 18
     }
12 19
 }