From 04adb2ab3ade23efa245ff8fbc29e7a3178cfb63 Mon Sep 17 00:00:00 2001 From: wandoubaba Date: Sat, 17 Aug 2024 21:23:18 +0800 Subject: [PATCH] collections/List.kt --- kotlinstudy/collections/List.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 kotlinstudy/collections/List.kt diff --git a/kotlinstudy/collections/List.kt b/kotlinstudy/collections/List.kt new file mode 100644 index 0000000..de311e7 --- /dev/null +++ b/kotlinstudy/collections/List.kt @@ -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 = mutableListOf("triangle", "square", "circle") + println(shapes) + shapes.add("pentagon") + println(shapes) + shapes.remove("circle") + println(shapes) + +} \ No newline at end of file