text Scala笔记

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text Scala笔记相关的知识,希望对你有一定的参考价值。

// Parameterize arrays with types

val greetStrings = new Array[String](3)

greetStrings(0) = "Hello"
greetStrings(1) = ","
greetStrings(2) = "World!\n"

for ( i <- 0 to 2){
  println ( greetStrings(i) )
}

// Scala doesn’t technically have operator overloading

// Array with initialization
val numNames = Array("zero", "one", "two")

//Scala Lists are always immutable
// LIST

val oneTwo = List(1, 2)
val threeFour = List(3, 4)
val oneTwoAndThreeFour = oneTwo ::: threeFour

println(oneTwo + " and " + threeFour + "are not mutate")
println("Thus" + oneTwoAndThreeFour + "is a new List")

// cons.” Cons prepends a new element to the beginning of an existing list

val twoThree = List(2, 3)
val oneTwoThree = 1 :: twoThree
println(oneTwoThree)

val oneTwoThree = 1 :: 2 :: 3 :: Nil
println(oneTwoThree)

// Note: Class List does offer an “append” operation
// ListBuffer, a mutable list that does offer an append operation

//Like lists, tuples are immutable, but unlike lists, tuples can contain different types of elements.
val pair = (99, "Luftballons")
println(pair._1)
println(pair._2)

Note:
  -- Arrays always mutable
  -- List always immutable
  -- sets and maps having both mutable and immutable
  
//sets and maps
  -- Set
    -- immutable set when you using + operator, it will create new set
    -- mutable set when you are using + operator it will return same set with added element
    

以上是关于text Scala笔记的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Zeppelin/Spark/Scala 中漂亮地打印数据框?

Scala语言学习笔记一

Scala系列Scala学习笔记

Scala学习笔记

Spark基础学习笔记04:Scala简介与安装

Scala笔记整理:Scala集合库