码迷,mamicode.com
首页 > 其他好文 > 详细

Scala function programming

时间:2014-10-07 00:25:22      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   java   for   strong   sp   

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 = 0
3     for(arg <- args) result += arg
4     result    
5 }
 
  scala Array Buffer to Java List:
1 import scala.collection.JavaConversions.bufferAsJavaList
2 import scala.collection.mutable.ArrayBuffer
3 val command = ArrayBuffer("ls","-al","/home/mike")
4 val pb = new ProcessBuilder(command)

  reverse operation

1 import scala.collection.JavaConversion.asScalaBuffer
2 import scala.collection.mutable.Buffer
3 val cmd:Buffer[String] = pb.command()

  Hash Map

1 val hs01 = Map("s01" -> 342342,"s02" -> 4245)
2 hs01.getOrElse("s01",0)

 

Scala function programming

标签:style   blog   color   io   ar   java   for   strong   sp   

原文地址:http://www.cnblogs.com/mikedeng/p/4008808.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!