Kotlin的list

list

fun main(args:Array<String>){
    var lists= listOf<String>("鸡蛋","大米","冰淇淋")    //创建list集合
    for(list in lists){                                 //遍历
      println(list)
    }
}

fun main(args:Array<String>){
var lists= listOf<String>("鸡蛋","大米","冰淇淋")
for(list in lists.withIndex()){ //带下标遍历
println(list)
}
}

//输出的结果
IndexedValue(index=0, value=鸡蛋)
IndexedValue(index=1, value=大米)
IndexedValue(index=2, value=冰淇淋)

fun main(args:Array<String>){
var lists= listOf<String>("鸡蛋","大米","冰淇淋")
for((i,e) in lists.withIndex()){ //将下标和值一起打印
println( "$i $e")
}
}
//输出结果
0 鸡蛋
1 大米
2 冰淇淋

map

fun main(args:Array<String>){
  var map=TreeMap<String,String>()
    map["1"]="good"
    map["2"]="day"
    map["3"]="yes"
    map["4"]="no"
    println(map["1"])
}

 

posted @ 2020-05-20 01:01  卑微小生  阅读(1838)  评论(0编辑  收藏  举报