LoginSignup
12
12

More than 5 years have passed since last update.

HadoopのWordCountをJava8のStreamで実装してみた

Last updated at Posted at 2014-05-27

勉強がてら、Java8のStreamを使ってHadoopのサンプルコードのWordCountを実装してみた。
@daiki_kameyaに手伝ってもらった。

    public static void main(String[] args) throws Exception {
        Path path = FileSystems.getDefault().getPath("input.txt");

        Files.lines(path).flatMap(line -> Arrays.stream(line.split(" ")))
                .collect(Collectors.groupingBy(s -> s, Collectors.counting()))
                .forEach((k, v) -> System.out.println(k + ":" + v));
    }
12
12
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12