41 lines
987 B
Text
41 lines
987 B
Text
/* NetRexx */
|
|
options replace format comments java crossref symbols nobinary
|
|
|
|
vals = [ 'zero', 'one', 'two', 'three', 'four', 'five' ]
|
|
keys = [ 'k0', 'k1', 'k2', 'k3', 'k4', 'k5' ]
|
|
hash1 = Rexx
|
|
hash2 = Map
|
|
|
|
hash1 = HashMap()
|
|
hash2 = ''
|
|
makeHash(hash1, keys, vals) -- using a Map object (overloaded method)
|
|
makeHash(hash2, keys, vals) -- using a Rexx object (overloaded method)
|
|
|
|
return
|
|
|
|
-- Using a Java collection object
|
|
method makeHash(hash = Map, keys = Rexx[], vals = Rexx[]) static
|
|
loop k_ = 0 to keys.length - 1
|
|
hash.put(keys[k_], vals[k_])
|
|
end k_
|
|
|
|
key = Rexx
|
|
loop key over hash.keySet()
|
|
say key.right(8)':' hash.get(key)
|
|
end key
|
|
say
|
|
|
|
return
|
|
|
|
-- For good measure a version using the default Rexx object as a hash (associative array)
|
|
method makeHash(hash = Rexx, keys = Rexx[], vals = Rexx[]) static
|
|
loop k_ = 0 to keys.length - 1
|
|
hash[keys[k_]] = vals[k_]
|
|
end k_
|
|
|
|
loop key over hash
|
|
say key.right(8)':' hash[key]
|
|
end key
|
|
say
|
|
|
|
return
|