forked from studoverse/Kotlift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path28_set.kt
45 lines (39 loc) · 934 Bytes
/
28_set.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
import java.util.*
fun main(args: Array<String>) {
// Constructors
val hashSet0 = HashSet<String>()
val linkedHashSet0 = LinkedHashSet<String>()
val set0 = emptySet<String>()
val set1 = setOf(1)
val set2 = setOf(1, 2, 1)
var hashSet = hashSetOf(1)
var linkedSet = linkedSetOf(2)
var mutableSet = mutableSetOf(3)
// Basic calls
println("${set1} (1)")
println("${set2} (1, 2)")
println("${set2.size} (2)")
hashSet.add(2)
linkedSet.addAll(linkedSet)
mutableSet.remove(3)
println(hashSet)
if (hashSet.size != 2) {
println("ERROR: hashSet.size")
}
println(linkedSet)
if (linkedSet.size != 1) {
println("ERROR: linkedSet.size")
}
println(mutableSet)
if (mutableSet.size != 0) {
println("ERROR: mutableSet.size")
}
if (!set0.isEmpty()) {
println("ERROR: set0.isEmpty()")
}
println("${hashSet} ([2, 1])")
// Iteration
for (k in set2) {
println("$k")
}
}