September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,35 @@
|
|||
// empty map
|
||||
var emptyMap = new HashMap<String, Integer>()
|
||||
|
||||
// map initialization
|
||||
var map = {"Scott"->50, "Carson"->40, "Luca"->30, "Kyle"->38}
|
||||
|
||||
// map key/value assignment
|
||||
map["Scott"] = 51
|
||||
|
||||
// get a value
|
||||
var x = map["Scott"]
|
||||
|
||||
// remove an entry
|
||||
map.remove("Scott")
|
||||
|
||||
// loop and maps
|
||||
for(entry in map.entrySet()) {
|
||||
print("Key: ${entry.Key}, Value: ${entry.Value}")
|
||||
}
|
||||
|
||||
// functional iteration
|
||||
map.eachKey(\ k ->print(map[k]))
|
||||
map.eachValue(\ v ->print(v))
|
||||
map.eachKeyAndValue(\ k, v -> print("Key: ${v}, Value: ${v}"))
|
||||
var filtered = map.filterByValues(\ v ->v < 50)
|
||||
|
||||
// any object can be treated as an associative array
|
||||
class Person {
|
||||
var name: String
|
||||
var age: int
|
||||
}
|
||||
// access properties on Person dynamically via associative array syntax
|
||||
var scott = new Person()
|
||||
scott["name"] = "Scott"
|
||||
scott["age"] = 29
|
||||
Loading…
Add table
Add a link
Reference in a new issue