标签:
def main(args: Array[String]): Unit = {
val triple = (100, "Scala", "Spark");
println(triple._1)
println(triple._2)
println(triple._3)
}
}
|
100
Scala
Spark
|
def main(args: Array[String]): Unit = {
val array = Array(1, 2, 3, 4, 5)
for (i <- 0 to (array.length - 1)) {
println("i = " + array(i));
}
}
|
i = 1
i = 2
i = 3
i = 4
i = 5
|
def main(args: Array[String]): Unit = {
val array = Array(1, 2, 3, 4, 5)
for (elem <- array) {
println(elem);
}
}
|
def main(args: Array[String]): Unit = {
var ages = Map("Rocky" -> 27, "Spark" -> 5)
for ((k, v) <- ages) {
println("Key is " + k + ", value is " + v)
}
}
|
Key is Rocky, value is 27
Key is Spark, value is 5
|
import scala.io.Source
object Test {
def main(args: Array[String]): Unit = {
val file = Source.fromFile("d:\\users.txt")
for (line <- file.getLines()) {
println(line);
}
}
}
|
import scala.io.Source
object Test { def main(args: Array[String]): Unit = { val file = Source.fromURL("https://www.baidu.com/") for (line <- file.getLines()) { println(line); } } } |
DT大数据梦工厂的微信公众号是DT_Spark,每天都会有大数据实战视频发布,请您持续学习。
Scala 深入浅出实战经典(1-64讲)完整视频、PPT、代码下载:
腾讯微云:http://url.cn/TnGbdC
360云盘:http://yunpan.cn/cQ4c2UALDjSKy 访问密码 45e2
|
03Scala学习: Tuple、Array、Map与文件操作入门实战
标签:
原文地址:http://www.cnblogs.com/wangshuo1/p/4677619.html