Array is mutable, but fixed length. Which means you can modify items in the Array, but you cannot add / remove item;
// Array is fixed length, you cannot add or remove item val ary: Array<String> = arrayOf("Wan", "Zhen", "Tian") ary[1] = "gg" println(ary.contains("gg")) // true val mixedAry = arrayOf("Zhen", 23, true) val numAry: IntArray = intArrayOf(1,2,3) // doubleArrayOf ... val states = arrayOf("NIVDA", "APPLA") val allStates = states + ary // concat Array of string println(allStates.size) // 5
List is immutable, you cannot reassign value for list itenm ,you cannot add / remove item;
val list: List<String> = listOf("Wan", "Zhen", "Tian") // list[0] = "gg" // ERROR:: List is immutable val list2: List<String> = listOf("Wan2", "Zhen2", "Tian2") val allList = list + list2 println(allList.size) // 6 println(allList.isEmpty()) // false println(allList.contains("Wan")) // true
ArrayList is mutable, you can add / remove itmes from ArrayList:
// arrayList is mutatable val aryList = arrayListOf("Wan", "Zhen", "Tian") aryList.add("Josh") aryList.add(1, "Jack") println(aryList) // [Wan, Jack, Zhen, Tian, Josh] println(aryList.remove("Wan")) // true val subList = aryList.subList(1, 2) println(subList) // ["Jack"]