Created
April 20, 2015 03:10
-
-
Save tokuhirom/913c87dd1698fd1ba758 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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