SCALA入门(3)
这一节学习TUPLE,ARRAY,MAP
Tuplepackage com.scala.study object HelloScala { def main(args:Array[String]){ var pair = (100,"Scala","Spark") println(pair._1) println(pair._2) } }Array
package com.scala.study object HelloScala { def main(args:Array[String]){ var array = Array(1,2,3,4,5) for(i<-0 until array.length){ println(array(i)) } for(elem<-array) println(elem) } }Map
package com.scala.study object HelloScala { def main(args:Array[String]){ var ages = Map("Rocky"->27,"Spark"->5) for((k,v)<-ages){ println("Key is" + k +",value is "+ v) } for((k,_)<-ages){ println("Key is" + k ) } } }
文件操作
package com.scala.study import scala.io.Source object HelloScala { def main(args: Array[String]) { var file = Source.fromFile("E:\\temp.txt"); for (line <- file.getLines()) println(line) var file1 = Source.fromURL("http://spark.apache.org/") for (line <- file1.getLines()) println(line) } }
相关推荐
匆匆那些年 2020-10-15
TheBigBlue 2020-07-28
shenwenjie 2020-07-07
muhongdi 2020-07-07
waitwolf 2020-07-08
yunfenglee 2020-07-08
yunfenglee 2020-07-08
kekeromer 2020-07-08
匆匆那些年 2020-07-07
liqinglin0 2020-07-05
TheBigBlue 2020-07-05
kekeromer 2020-06-13
zhixingheyitian 2020-06-08
TheBigBlue 2020-06-06
liqinglin0 2020-06-01
liqinglin0 2020-06-01
yunfenglee 2020-05-30
MICKEYSTUDY 2020-05-28
muhongdi 2020-05-19