From d75c073dfac2b4b6848c41ac37a7dce5b491fab9 Mon Sep 17 00:00:00 2001 From: luming Date: Wed, 30 Jun 2021 17:13:20 +0800 Subject: [PATCH] map --- src/senior/Collection/CollectioMap.kt | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/senior/Collection/CollectioMap.kt b/src/senior/Collection/CollectioMap.kt index 3035e97..9f2769e 100644 --- a/src/senior/Collection/CollectioMap.kt +++ b/src/senior/Collection/CollectioMap.kt @@ -4,7 +4,9 @@ fun main(args: Array) { // 不可变map var m: Map = mapOf("a" to "A", "b" to "B", "c" to "C") println(m) - + m.forEach{ + println("key = ${it.key}, value = ${it.value}") + } println(m.get("a")) // 可变map var map: MutableMap = mutableMapOf() @@ -12,5 +14,21 @@ fun main(args: Array) { map.put("pig", "猪") println(map) + // 集合大小 + println("map size = " + map.size) + println(map.get("pig")) + + // 获取所有的键 + var keys = map.keys + println(keys) + // 获取所有的值 + var values = map.values + println(values) + + // 遍历map + var entries = map.entries + entries.forEach{ + println("key = ${it.key},value = ${it.value}") + } } \ No newline at end of file