Last active
April 9, 2017 08:00
-
-
Save SoltauFintel/a6d23427515848f4c0e7ed4ddf8c80a4 to your computer and use it in GitHub Desktop.
Häufigkeiten: Anzahl der Vorkommnisse eines Textes zählen und anschließend sortiert ausgeben
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private final Multiset<String> set = HashMultiset.create(); // 'com.google.guava:guava:21.0' | |
public void add(String item) { | |
set.add(item); | |
} | |
public void print() { | |
set.entrySet().stream() | |
.sorted((a, b) -> b.getCount() - a.getCount()) | |
.forEach(e -> System.out.println(Strings.padStart("" + e.getCount(), 6, ' ') + "x " + e.getElement())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment