自学内容网 自学内容网

scala

package test_33
  import scala.io.Source

object test {
  def main(args: Array[String]): Unit = {
    val content = Source.fromFile("1.txt").mkString

    val arr = content.split("\\W+")
    arr.foreach(println)

    val arr1 = Array("thank", "you", "very", "much", "thank", "very")

    val m1 = scala.collection.mutable.Map[String, Int]()
    arr1.foreach(word => {
      if (m1.contains(word)) {
        m1(word) += 1
      } else {
        m1(word) = 1
      }
    })

    m1.foreach{ case (word,cishu) => println(s"${word}: ${cishu}")}
  }
}

原文地址:https://blog.csdn.net/wjwjssjjs/article/details/144084673

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!