Skip to content

Instantly share code, notes, and snippets.

@tokuhirom
Created April 20, 2015 03:10
Show Gist options
  • Save tokuhirom/913c87dd1698fd1ba758 to your computer and use it in GitHub Desktop.
Save tokuhirom/913c87dd1698fd1ba758 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.stream.Collectors;
public class Hoge {
public static void main(String[] args) throws IOException {
Files.readAllLines(Paths.get(args[0])).stream()
.flatMap(line -> Arrays.stream(line.split("\\W+")))
.filter(word -> !word.isEmpty())
.collect(Collectors.groupingBy(r -> r, Collectors.counting())).entrySet()
.stream().sorted((a, b) -> (int)(a.getValue() - b.getValue()))
.forEach(it -> System.out.println(it.getValue() + ":"
+ it.getKey()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment