-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollection.html
More file actions
151 lines (134 loc) · 6.04 KB
/
collection.html
File metadata and controls
151 lines (134 loc) · 6.04 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html lang="en">
<head>
<title>Class Kotlin</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Merriweather+Sans:400,300,700" type="text/css">
<link rel="stylesheet" href="static/app.css" type="text/css">
<link rel="shortcut icon" href="static/logo.png" />
<meta name="theme-color" content="#111111">
<meta name="og:type" content="website">
<meta name="og:title" content="MoraSoftware.github.io">
<meta name="og:description" content="Mora Software">
<meta name="og:site_name" content="Mora Software">
<meta name="og:url" content="{{ site.url }}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="block">
<form action="index.html">
<input type="image" src="static/white.jpg" />
</form>
</div>
<div class="block">
<h2>Collection Kotlin</h2>
</div>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#init">Collection</a></li>
<li><a data-toggle="tab" href="#list">List</a></li>
<li><a data-toggle="tab" href="#map">Map</a></li>
<li><a data-toggle="tab" href="#set">Set</a></li>
</ul>
<div class="tab-content">
<div id="init" class="tab-pane fade in active">
<h3>Array</h3>
<xmp>
fun main(args: Array<String>) {
// Elements : 32 0 0 54 0
// Index : 0 1 2 3 4
var myArray = Array<Int>(5) { 0 } // Mutable. Fixed Size.
myArray[0] = 32
myArray[3] = 54
myArray[1] = 11
for (element in myArray) { // Using individual elements (Objects)
println(element)
}
println()
for (Index in 0..myArray.size - 1) {
println(myArray[index])
}
}
</xmp>
<hr>
<p>Collection</p>
</div>
<div id="list" class="tab-pane fade">
<h3>List</h3>
<xmp>
fun main(args: Array<String>) {
// Elements :
// Index : 0 1 2 3 4
// var list = mutableListOf<String>() // Mutable, No Fixed Size, Can Add or Remove Elements
// var list = arrayListOf<String>() // Mutable, No Fixed Size, Can Add or Remove Elements
var list = ArrayList<String>() // Mutable, No Fixed Size, Can Add or Remove Elements
list.add("Yogi") // 0
list.add("Manmohan") // 1
list.add("Vajpayee") // 2
// list.remove("Manmohan")
// list.add("Vajpayee")
list[1] = "Modi"
for (element in list) { // Using individual elements (Objects)
println(element)
}
}
</xmp>
<hr>
<p>listOf </p>
<p>Inmutable, Fixed Size, Read ONLY</p>
<p>mutableListOf, arrayListOf, ArrayList</p>
<p>Mutable, READ and WRITE both, No Fixed Size</p>
</div>
<div id="map" class="tab-pane fade">
<h3>Map</h3>
<xmp>
// Map Tutorial: Key-Value pair
// var myMap = HashMap<Int, String>() // Mutable, READ and WRITE both, No Fixed Size
// var myMap = mutableMapOf<Int, String>() // Mutable, READ and WRITE both, No Fixed Size
var myMap = hashMapOf<Int, String>() // Mutable, READ and WRITE both, No Fixed Size
myMap.put(4, "Yogi")
myMap.put(43, "Manmohan")
myMap.put(7, "Vajpayee")
myMap.put(43, "Modi")
for (key in myMap.keys) {
println("Element at $key = ${myMap[key]}") // myMap.get(key)
}
</xmp>
<hr>
<p>mapOf </p>
<p>Inmutable, Fixed Size, Read ONLY</p>
<p></p>
<p>HashMap, mutableMapOf, hashMapOf</p>
<p>Mutable, READ and WRITE both, No Fixed Size</p>
</div>
<div id="set" class="tab-pane fade">
<h3>Set</h3>
<xmp>
fun main(args: Array<String>) {
// "Set" contains unique elements
// "HashSet" also contains unique elements but sequence is not guaranteed in output
var mySet = mutableSetOf<Int>( 2, 54, 3, 1, 0, 9, 9, 9, 8) // Mutable Set, READ and WRITE both
// var mySet = hashSetOf<Int>( 2, 54, 3, 1, 0, 9, 9, 9, 8) // Mutable Set, READ and WRITE both
mySet.remove(54)
mySet.add(100)
for (element in mySet) {
println(element)
}
}
</xmp>
<hr>
<p>setOf -> contains unique elements</p>
<p>Inmutable, Fixed Size, Read ONLY</p>
<p></p>
<p>Set -> contains unique elements</p>
<p>HashSet -> also contains unique elements but sequence is not guaranteed in output</p>
<p>Mutable, READ and WRITE both, No Fixed Size</p>
</div>
</div>
</div>
</body>
</html>