
scala
文章平均质量分 84
君子剑岳不群
这个作者很懒,什么都没留下…
展开
-
scala--集合
val x = Vector(1, 2, 3)x.sum // 6x.filter(_ > 1) // Vector(2, 3)x.map(_ * 2) // Vector(2, 4, 6)x.takeWhile(_ < 3) // Vector(1, 2)immutable :ArraySeq属于IndexedSeq,底层数组实现,随机查找性能高,写操作需要线性时间LazyList属于L原创 2021-04-06 21:02:11 · 107 阅读 · 0 评论 -
scala--方法
def isBetween(a: Int, x: Int, y: Int) = a >= x && a <= y可以不带返回值类型但是最好写上val convert1to5 = new PartialFunction[Int, String] {val nums = Array(“one”, “two”, “three”, “four”, “five”)def apply(i: Int) = nums(i-1)def isDefinedAt(i: Int) = i &g原创 2021-04-03 19:00:43 · 169 阅读 · 0 评论 -
scala--类和枚举
主构造器:VisibilityAccessor?Mutator?var是是val是否no var or val否否Adding the private keyword to var or val否否在类里面,无论上述条件如何,都可以访问和修改Case classes默认什么都不加的话是val,例如:case class Person(name: String)scala> val p = Person(“Dale Cooper”)原创 2021-04-01 10:44:29 · 102 阅读 · 0 评论 -
scala--控制结构
for i <- List(1, 2, 3) do println(i)fori <- 1 to 10if i > 3if i < 6doprintln(i)val listOfInts = fori <- 1 to 10if i > 3if i < 6yieldi * 10def isTrue(a: Matchable): Boolean = a matchcase 0 | “” => falsecase _ => tru原创 2021-03-31 13:09:03 · 93 阅读 · 0 评论 -
scala-Numbers和Dates
“1”.toByte // Byte = 1“1”.toShort // Short = 1“1”.toInt // Int = 1“1”.toLong // Long = 1“1”.toFloat // Float = 1.0“1”.toDouble // Double = 1.0“hello!”.toInt // java.lang.NumberFormatException“1”.toByteOption // Option[Byte原创 2021-03-30 00:02:51 · 240 阅读 · 0 评论 -
scala--String
val h = "Hello"f"'$h%s'" // 'Hello'f"'$h%10s'" // ' Hello'f"'$h%-10s'" // 'Hello '原创 2021-03-28 12:15:46 · 603 阅读 · 0 评论