1、Tuple操作
def main(args: Array[String]): Unit = {
val tuple = ("yy","hello","world");
println(tuple._1);
println(tuple._2);
println(tuple._3);
println(tuple.toString());
}
结果如下:
yy
hello
world
(yy,hello,world)
2、Array操作
def main(args: Array[String]): Unit = {
val array = Array(1,2,3,4,5);
for(i <-0 until array.length){
print(array(i)+ " ");
}
for(element <-array){
println(element)
}
}
3、Map操作
def main(args: Array[String]): Unit = {
val map = Map("name"->"yy","age"->26);
for((k,v)<-map){
println("Key is " + k +",value is " + v);
}
//占位符
for((k,_)<-map){
println("Key is " + k );
}
}
4、文件操作
def main(args: Array[String]): Unit = {
val file = Source.fromFile("D:\\ww\\test.txt","GBK");
for(line <- file.getLines()){
println(line);
}
}