
scala
Joy CR
欢迎关注我的公众号: 小秋的博客
https://blog.youkuaiyun.com/xiaoqiu_cr
https://github.com/crr121
https://segmentfault.com/u/chenrong_flying
联系邮箱:rongchen633@gmail.com
展开
-
Scala数组
1、数组的定义和取值object helloworld { def main(args: Array[String]) { //java: int[] arr = new int[10]; // int[] arr = new int[]{1,2,3,4} // int[] arr = {1,2,3,4} //scala://原创 2017-11-17 15:50:29 · 342 阅读 · 0 评论 -
Scala-过程与异常
1、过程没有返回值和等号object helloworld { def main(args: Array[String]) { def out(a:Int): Unit ={ println("打印输出a****"+a); } println("过程的返回值===="+out(2)); }}打印输出a****2过程的返回值====()Process fi原创 2017-11-17 09:37:20 · 395 阅读 · 0 评论 -
scala-包
1、包的嵌套定义//scala里面包可以定义包//然后包里面可以定义对象package a{ package aa{ object A{ def main(args: Array[String]): Unit = { println("hwloo"); } } }}2、 3、如果一个方法没有定义方法体,则该方法所在原创 2017-11-22 15:52:27 · 173 阅读 · 0 评论 -
python-数字
1、创建数值对象并且更新对象a = 1;print id(a);#49249632a += 1;print id(a);#49249620#由于数值对象是不可更改的对象,所以第二次赋值的时候实际上是创建了一个新的对象让变量a指向了新的对象原创 2017-11-23 14:23:09 · 259 阅读 · 0 评论 -
Scala-文件操作
1、读取文件import scala.io.Sourceobject Model { def main(args: Array[String]): Unit = { val s = Source.fromFile("d:/hello.txt"); val lines = s.getLines(); for (line<-lines){ print(line+"原创 2017-11-23 15:03:16 · 386 阅读 · 0 评论 -
Scala-trait
1、trait的扩展 一个用extends 多个用with 同时还存在自身扩展原创 2017-11-23 16:13:01 · 474 阅读 · 0 评论 -
Scala-操作符
1、单元操作符,中置操作符,双元操作符,后置操作符object Operation { def main(args: Array[String]): Unit = { //中置操作符 + to..... //单元操作符 tostring val s = 1.toString; //!时布尔值取反 val flg = !true; println(原创 2017-11-24 09:11:37 · 339 阅读 · 0 评论 -
Scala高阶函数
1、高阶函数的定义:一个函数的返回值或者参数是一个函数,这样的函数就称作高阶函数object Fraction { def main(args: Array[String]): Unit = { val f = add _;//这里的f是一个函数,将函数赋值给一个变量 //这里的f是一个函数类型的变量 //这里的下划线表示取出函数本身 val result = f原创 2017-11-24 11:07:42 · 305 阅读 · 0 评论 -
Scala-操作符
1、单元操作符,中置操作符,双元操作符,后置操作符object Operation { def main(args: Array[String]): Unit = { //中置操作符 + to..... //单元操作符 tostring val s = 1.toString; //!时布尔值取反 val flg = !true; p原创 2017-11-23 16:32:22 · 336 阅读 · 0 评论 -
Scala对象
1、object对象object helloworld { def main(args: Array[String]) { //由于Scala没有静态概念,所以静态属性可以通过object来实现 //编译完成之后会生成对应的类,方法都是静态方法,非静态成员对应到单例类中 //单例类以Person$为类名称 object Pe原创 2017-11-22 11:24:10 · 412 阅读 · 0 评论 -
Scala-函数
1、定义函数object helloworld { def main(args: Array[String]) { //定义函数 def add(a:Int,b:Int):Int = { var c = a + b; return c; } print(add(1,2)); }}---不写返回值 returnobject hello原创 2017-11-16 17:30:41 · 280 阅读 · 0 评论 -
Scala与Java的交互
1、list类型和buffer的自动转换import scala.collection.mutable.ArrayBuffer import scala.collection.JavaConverters.asScalaBuffer import java.util.List object helloworld { def main(args: Array[Stri原创 2017-11-17 16:09:30 · 385 阅读 · 0 评论 -
Scala元组和映射
1、map映射import scala.collection.mutable._//如果要定义一个map为可变的需要导入mutable包 object helloworld { def main(args: Array[String]) { val map1 = scala.collection.immutable.Map[Int,String](100->"che原创 2017-11-17 17:17:42 · 324 阅读 · 0 评论 -
Scala数组的拉链操作
1、两个数组的咬合操作(拉链操作) object helloworld { def main(args: Array[String]) { val husband = Array("牛郎","李亚鹏","张杰"); val wife = Array("织女","王菲","谢娜"); val both = husband.zip(wif原创 2017-11-17 17:34:31 · 3109 阅读 · 0 评论 -
Scala-集合
1、空集合Nil,以及右结合object controllAbstract { def main(args: Array[String]): Unit = { //向空集合Nil中添加元素 //双冒号是右结合 // println((1::2::Nil)); //List(1, 2) val list = List(1,2,4); val list1原创 2017-11-29 10:48:02 · 265 阅读 · 0 评论 -
Scala-类
1、OOP对象属性与方法object helloworld { def main(args: Array[String]) { //定义一个对象,对象里面有私有属性和方法 class Person { //Scala里面的字段都包括了方法 私有属性val包括了get()和set()防范 //val 属性包括了get()方法原创 2017-11-20 15:52:46 · 272 阅读 · 0 评论 -
Scala-模式匹配
1、模式匹配 match caseobject controllAbstract { def main(args: Array[String]): Unit = { val x:Any="123"; x match { case a:Int=> println("++++"); case b:String=>println("----"); c原创 2017-11-30 09:45:58 · 328 阅读 · 0 评论 -
scala(一)
1、变量和常量scala> var a:String="hello"a: String = helloscala> var a="ji"a: String = jiscala> var a=1a: Int = 1scala> var a:Int=1--->可以定义变量的时候定义类型a: Int = 1scala> var a:Int=2a: Int = 2scala> var a="hel原创 2017-11-16 12:01:09 · 1134 阅读 · 0 评论 -
Scala--循环
1、for循环 //to [] 闭区间 //for ( x<- 1 to 10) println(x); //until [)左闭右开区间 for(x<- 1 until 10) println(x);2、Scala没有break和continue,可以使用Breaks对象的break()方法import util.control.Breaks._object hel原创 2017-11-16 15:05:24 · 282 阅读 · 0 评论 -
Scala-高阶函数
map的方法filter 3、object gaojie { def main(args: Array[String]): Unit = { (1 to 10).map("*" * _).foreach(println _); //数组1 到 10 调用高阶函数map()映射 将每一行乘以对应的* //然后在依次打印这个数组 }} 4、reduce化简objec原创 2017-11-28 10:47:41 · 253 阅读 · 0 评论