摘要: 1.Scala 的main函数入口 如果想一个类里面既想有静态又想有非静态的方法,那么就要写同名的伴生类,如下: 2.Scala 的List 默认list 的容量有限,不能随便扩容 如果想扩容: import scala.collection.mutable.ListBuffer var arr = 阅读全文
posted @ 2019-03-10 22:15 飞小白 阅读(255) 评论(0) 推荐(0) 编辑
摘要: 1.匹配字符串 A => 1 B => 2 C=> 3 //传统方法 def getNum(msg:String):Int={ if(msg=="A") 1 else if (msg=="B") 2 else if (msg=="C") 3 else 4 } //模式匹配方法 def getNum( 阅读全文
posted @ 2019-03-10 22:03 飞小白 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 1.类的定义和对象的创建 没有修饰,默认public class Person{ private var id = 0 var name= "tom" def setId(id:Int) = this.id = id def getId() = this.id } var p = new Perso 阅读全文
posted @ 2019-03-10 22:02 飞小白 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 1.Map 将用:转换数据 var arr=Array(1 to 10 :_*) arr.foreach(println) arr.map((n:Int) => n*2) //给map一个匿名函数,将map遍历的每一个值x2 会返回一个arr res1: Array[Int] = Array(2, 阅读全文
posted @ 2019-03-10 22:01 飞小白 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 1.匿名函数 函数在内存当作是以对象的形式存在的,既然是对象就可以以变量指向对象来引用函数 //第一种方式 def add(n:Int,m:Int):Int = m+n var f = add _ 结果 add: add[](val n: Int,val m: Int) => Int f: (Int 阅读全文
posted @ 2019-03-10 21:53 飞小白 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 1.Map 形式:Map(Key -> value, ...) val map = Map(1 -> "tom",2 ->"jack") Result: map: scala.collection.immutable.Map[Int,String] = Map(1 -> tom, 2 -> jack 阅读全文
posted @ 2019-03-10 21:52 飞小白 阅读(99) 评论(0) 推荐(0) 编辑