forked from studoverse/Kotlift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path27_map.kt
46 lines (40 loc) · 1.11 KB
/
27_map.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.*
fun main(args: Array<String>) {
// Constructors
val hashMap0 = HashMap<String, String>()
val linkedHashMap0 = LinkedHashMap<String, String>()
val map0 = emptyMap<String, String>()
val map1 = mapOf(Pair(10, "hi"))
val map2 = mapOf(Pair("as", "hi"), Pair("df", "hello"), Pair("gh", "salut"))
var hashMap = hashMapOf(Pair(1, "hi"))
var linkedMap = linkedMapOf(Pair(1, "hi"))
var mutableMap = mutableMapOf(Pair(1, "hi"))
// Basic calls
println("${map1[10]} (hi)")
println("${map2["as"]} (hi)")
println("${map2.size} (3)")
hashMap.put(2, "hello")
linkedMap.putAll(linkedMap)
mutableMap.remove(1)
println(hashMap)
if (hashMap.size != 2) {
println("ERROR: hashMap.size")
}
println(linkedMap)
if (linkedMap.size != 1) {
println("ERROR: linkedMap.size")
}
println(mutableMap)
if (mutableMap.size != 0) {
println("ERROR: mutableMap.size")
}
if (!map0.isEmpty()) {
println("ERROR: map0.isEmpty()")
}
println("${hashMap.keys} ([2, 1])")
println("${hashMap.values} ([hello, hi])")
// Iteration
for ((k, v) in map2) {
println("$k : $v")
}
}