直接上代码,比较直观,有些时候,看理论的东西说好多不如直接上手写一下,简单粗暴,
package com.test.zhuoer
import scala.reflect.internal.util.HashSet
object ScalaListTest {
def main(args: Array[String]): Unit = {
println("---------------------Array------------------------------")
/**
* **
* 数组的使用
*/
var array = new Array[String](3)
array(0) = "test1"
array(1) = "test2"
array(2) = "test3"
for (i <- 0 to array.length - 1) {
println(array(i))
}
println("---------------------List-------------------------------")
/**
* *
* List的使用
*/
var list1 = List("aaa", "bbb", "ccc") //添加数据
var list2 = List("ddd") //添加数据
var list3 = List("eee", "fff") //添加数据
var list4 = list1 ::: list2 ::: list3 //合并数据
list4.foreach(list4 => println(list4 + " "))
println("------------------Set----------------------------------")
/**
* **
* Set的使用
*/
var set = Set("Beijing", "Shanghai")
set += "QIQIHAER"
set.foreach(value => println(value + " "))
println("Is contains QIQIHAER " + set.contains("QIQIHAER"))
println("-------------------Map---------------------------------")
val map = Map(1 -> "AAA", 2 -> "BBB", 3 -> "CCC", 4 -> "DDD", 5 -> "EEE")
println("............map")
map.foreach(map => println("key=" + map._1 + " val=" + map._2))
var map1 = Map[Int, String]()
map1 += (1 -> "AAAA")
map1 += (2 -> "BBBB")
map1 += (3 -> "CCCC")
map1 += (4 -> "DDDD")
println("............map1")
map1.foreach(map1 => {
println("key=" + map1._1 + " val=" + map1._2)
})
}
}