Scala Array

原创转载请注明出处: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!

  

猜你喜欢

转载自agilestyle.iteye.com/blog/2331948
今日推荐