对于初学者来说写好一个scala的wordcount也是一个不容易的事情,一下是对两个方面来写一下scala中的Wordcount
数据的使用:
hello hive good
mand good mand
good good
mand hello hive
完整代码的编写:
import scala.io.Source
object TestWorldCount {
def main(args: Array[String]): Unit = {
/**
* 读取文件中的数据,把它们每行的数据的内容都读出来,然后把每行的数据都读出来,然后放入到list中
* 使用""""""三个引号在scala中可以不用写转义字符
* 结果:List(hello hive good, mand good mand , good good, mand hello hive)
*/
<span style="background-color: rgb(255, 255, 0);">val list = Source.fromFile("""d:\world.txt""").getLines.toList</span>
/**