柚子快報激活碼778899分享:開發(fā)語言 后端 scala練習(xí)
柚子快報激活碼778899分享:開發(fā)語言 后端 scala練習(xí)
需求一:wordCount
Scalapackage com.doit.day03import scala.io.{BufferedSource, Source}object WordCountDemo {
? def main(args: Array[String]): Unit = {
??? //讀取文件,獲取到一個Source對象??? val source: BufferedSource = Source.fromFile("D:\\develop\\ideaWorkSpace\\myself\\study\\scalaDemo\\data\\word.txt") ??? //調(diào)用getLines方法,獲取到每一行數(shù)據(jù),每一行數(shù)據(jù)都放在迭代器中??? val lines: Iterator[String] = source.getLines() ??? //如果我現(xiàn)在直接這么返回,他的返回值是什么???? Iterator[String]? ==》 同樣的返回一個迭代器,迭代器里面放得是Array[String] 數(shù)組里面每一個元素放得都是一個個的單詞??? val arrWord: Iterator[Array[String]] = lines.map(line => {
????? //1.需要將每一行數(shù)據(jù)拿出來進行切割,變成一個個的單詞????? //hello?? hadoop? hive????? val wordsArr: Array[String] = line.split("\\s+") ????? wordsArr ??? }) ??? //將迭代器轉(zhuǎn)換成了集合??? val list
柚子快報激活碼778899分享:開發(fā)語言 后端 scala練習(xí)
參考文章
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。
轉(zhuǎn)載請注明,如有侵權(quán),聯(lián)系刪除。