集合框架

集合框架的接口类型比对

集合框架的创建

//Java中创建List;
List<Integer> intList = new ArrayList<>(Arrays.asList(1,2,3));
val intList : List<Int> = listOf(1,2,3)

val intList2 : MutableList<Int> = mutableListOf(1,2,3)
val map : Map<String,Any> = mapOf("name" to "benny","age" to 20)

val map2 :Map<String,Any> = mutableMapOf = mutabllleMapOf("name" to +"benny","age tp )
//Any等价于Java的Object;
List<String> stringList = new ArrayList<>();

val stringList = ArrayList<String>()

框架的读写

1 . 添加

//Java中读写;
for(int i = 0;i < 10;i ++){
    stringList.add("num:" + i);
}
//Kotlin中读写;
for(i in 1 .. 10){
    stringList.add("num:"$i)
}

for(i in 0 .. 10){
    stringList += "num:$i"  //对于List而言,+= 等价于add;
}

2 . 删除

//Java中删除;
for(int i = 0;i < 10;i ++){
    stringList.remove("num:" + i);
}
//Kotlin中删除;
for(i in 0 .. 10){
    stringList.remove("num:$i")
}

for(i in 0 .. 10){
    stringList -= "num:$i"  //-= 等价于remove;
}

Pair

Tripe

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
---------------last line for now--------------