scala tips

集合

集合文档: https://docs.scala-lang.org/zh-cn/overviews/collections/introduction.html

seq文档:https://www.scala-lang.org/api/current/scala/collection/Seq.html

scala集合框架

模式匹配

优雅文件读取

import scala.io.Source
import scala.util.{Try,Success,Failure}

object Test extends App {

    def readTextFile(filename: String): Try[List[String]] = {
        Try(Source.fromFile(filename).getLines.toList)
    }

    val filename = "/etc/passwd"
    readTextFile(filename) match {
        case Success(lines) => lines.foreach(println)
        case Failure(f) => println(f)
    }

}

线程池

使用java并发包中的线程池工具 https://blog.csdn.net/liam08/article/details/101647064

其他资料

posted @ 2020-01-17 15:17  畑鹿驚  阅读(108)  评论(1编辑  收藏  举报