diff --git a/src/main/scala/top/fjy8018/scala/FunctionApp.scala b/src/main/scala/top/fjy8018/scala/FunctionApp.scala index fb21b93..a08dab3 100644 --- a/src/main/scala/top/fjy8018/scala/FunctionApp.scala +++ b/src/main/scala/top/fjy8018/scala/FunctionApp.scala @@ -1,5 +1,7 @@ package top.fjy8018.scala +import scala.io.Source + /** * F嘉阳 * 2018-11-25 20:21 diff --git a/src/main/scala/top/fjy8018/scala/WordCount.scala b/src/main/scala/top/fjy8018/scala/WordCount.scala new file mode 100644 index 0000000..198450c --- /dev/null +++ b/src/main/scala/top/fjy8018/scala/WordCount.scala @@ -0,0 +1,22 @@ +package top.fjy8018.scala + +import scala.io.Source + +/** + * wordcount + * F嘉阳 + * 2019-01-03 10:33 + */ +object WordCount { + + def main(args: Array[String]): Unit = { + wordCount() + } + + def wordCount(): Unit ={ + val txt = Source.fromFile("tmp/hello.txt").mkString + + val txts = List(txt) + txts.flatMap(_.split(",")).map(x => (x,1)).groupBy(_._1).mapValues(_.size).foreach(println) + } +}