Skip to content

gotta learn more about linked lists i guess #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
now working with linked list
  • Loading branch information
patglavin committed Mar 13, 2018
commit 6f47f4b2a9aa2d7a995e5d8e918b035721e6f6d8
14 changes: 9 additions & 5 deletions src/main/java/io/zipcoder/WC.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ public ArrayList<String> removePunctuation() {
return answer;
}

public HashMap<String, Integer> wordCount(){
public Map<String, Integer> wordCount(){
ArrayList<String> filtered = removePunctuation();
HashMap<String, Integer> answer = new HashMap<>();
Map<String, Integer> answer = new LinkedHashMap<>();
for (String word:filtered) {
if (!answer.containsKey(word)) answer.put(word, 1);
else answer.put(word, answer.get(word) + 1);
}
answer.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, HashMap::new));
return answer;
Map<String, Integer> sorted = answer.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
for (Map.Entry entry:sorted.entrySet()) {
System.out.println(entry.getKey() + " | " + entry.getValue());
}
return sorted;
}

}
Loading