package com /** * Created by ZX on 2016/4/5. */ object ListTest { def main(args: Array[String]) { //创建一个List val lst0 = List(1,7,9,8,0,3,5,4,6,2) //将lst0中每个元素乘以10后生成一个新的集合 val lst01=lst0.map(_ * 10) println("lst01"+lst01) val lst1 = lst0.map(x =…
package com /** * Created by ZX on 2015/11/6. */ object VariableDemo { def main(args: Array[String]) { //1定义变量----------------------------------------- //使用val定义的变量值是不可变的,相当于java里用final修饰的变量 val i = 1 //使用var定义的变量是可变得,在Scala中鼓励使用val var s = "hello&qu…
1 类的定义 package com /** * Created by Administrator on 2019/6/3. */ //类并不用声明为public. class Person { //用val修饰的变量是只读属性,有getter但没有setter //(相当与Java中用final修饰的变量) val id = "9527" //用var修饰的变量既有getter又有setter var age = 18 //类私有字段,只能在类的内部使用 private var na…
val lines=List("hello tom hello jerry","hello tom hello kitty hello china") //方法一: val wc=lines.flatMap(_.split(" ")).map((_,1)).groupBy(_._1).map(t=>(t._1,t._2.size)).toList.sortBy(_._2).reverse //方法二: val wc2=lines.flatM…
package com /** * Created by Administrator on 2019/4/8. */ object TestMap { def ttt(f: Int => Int): Unit = { val r = f(10) println(r) } val f0 = (x: Int) => x * x def m0(x: Int): Int = { x * 11 } def main(args: Array[String]) { // val arr=Array(1,2,…