MCPcopy Create free account
hub / github.com/careercup/ctci / setupDictionary

Method setupDictionary

java/Chapter 17/Question17_9/Question.java:8–20  ·  view source on GitHub ↗
(String[] book)

Source from the content-addressed store, hash-verified

6
7public class Question {
8 public static Hashtable<String, Integer> setupDictionary(String[] book) {
9 Hashtable<String, Integer> table = new Hashtable<String, Integer>();
10 for (String word : book) {
11 word = word.toLowerCase();
12 if (word.trim() != "") {
13 if (!table.containsKey(word)) {
14 table.put(word, 0);
15 }
16 table.put(word, table.get(word) + 1);
17 }
18 }
19 return table;
20 }
21 public static int getFrequency(Hashtable<String, Integer> table, String word) {
22 if (table == null || word == null) {
23 return -1;

Callers 1

mainMethod · 0.95

Calls 2

putMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected