collections/List.kt

This commit is contained in:
wandoubaba 2024-08-17 21:23:18 +08:00
parent 9a7ae56256
commit 04adb2ab3a

View File

@ -0,0 +1,19 @@
package kotlinstudy.collections
fun main() {
val readOnlyShapes = listOf("triangle", "square", "circle")
println(readOnlyShapes)
println("The 1st item in the list `readOnlyShapes` is: ${readOnlyShapes[0]}")
println("The last item in the list `readOnlyShapes` is: ${readOnlyShapes.last()}")
println("The list `readOnlyShapes` has ${readOnlyShapes.count()} items")
println("circle" in readOnlyShapes)
val shapes: MutableList<String> = mutableListOf("triangle", "square", "circle")
println(shapes)
shapes.add("pentagon")
println(shapes)
shapes.remove("circle")
println(shapes)
}