首页 > 代码库 > Scala function programming
Scala function programming
1. Arbitrary multi parameters funcs
sum(1,2,3,4,5) = sum(1 to 5: _*)
the equal ‘=‘ can be ignored if there is none return val
1 def sum(args: Int*) = {2 var result = 03 for(arg <- args) result += arg4 result 5 }
scala Array Buffer to Java List:
1 import scala.collection.JavaConversions.bufferAsJavaList2 import scala.collection.mutable.ArrayBuffer3 val command = ArrayBuffer("ls","-al","/home/mike")4 val pb = new ProcessBuilder(command)
reverse operation
1 import scala.collection.JavaConversion.asScalaBuffer2 import scala.collection.mutable.Buffer3 val cmd:Buffer[String] = pb.command()
Hash Map
1 val hs01 = Map("s01" -> 342342,"s02" -> 4245)2 hs01.getOrElse("s01",0)
Scala function programming
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。