原创转载请注明出处:http://agilestyle.iteye.com/blog/2331948
ScalaArray.scala
package org.fool.scala.basic
object ScalaArray {
def printArray(args: Array[String]) = args.foreach(print)
def main(args: Array[String]): Unit = {
val greetStrings1 = new Array[String](3)
greetStrings1(0) = "Hello"
greetStrings1(1) = ", "
greetStrings1(2) = "World!\n"
printArray(greetStrings1)
val greetStrings2 = new Array[String](3)
greetStrings2.update(0, "Hello")
greetStrings2.update(1, ", ")
greetStrings2.update(2, "world!\n")
printArray(greetStrings2)
val greetStrings3 = Array("Hello", ", ", "world!\n")
val greetStrings4 = Array.apply("Hello", ", ", "world!\n")
printArray(greetStrings3)
printArray(greetStrings4)
}
}
Console Output
Hello, World! Hello, world! Hello, world! Hello, world!
本文通过Scala语言展示了如何创建和操作数组,包括使用不同的方法初始化数组,并演示了更新数组元素的过程。
1307

被折叠的 条评论
为什么被折叠?



