Skip to content

Instantly share code, notes, and snippets.

@SoltauFintel
Last active April 9, 2017 08:00
Show Gist options
  • Save SoltauFintel/a6d23427515848f4c0e7ed4ddf8c80a4 to your computer and use it in GitHub Desktop.
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
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