This task is about arrays.

For hashes or associative arrays, please see Creating an Associative Array.

For a definition and in-depth discussion of what an array is, see Array.



Task

Show basic array syntax in your language.

Basically, create an array, assign a value to it, and retrieve an element   (if available, show both fixed-length arrays and
dynamic arrays, pushing a value into it).

Please discuss at Village Pump:   Arrays.

Please merge code in from these obsolete tasks:

   Creating an Array
   Assigning Values to an Array
   Retrieving an Element of an Array


Related tasks

   Collections
   Creating an Associative Array
   Two-dimensional array (runtime)


/* NetRexx */
options replace format comments java crossref symbols nobinary
 
array = int[10]
array[0] = 42
 
say array[0] array[3]
say
 
words = ['Ogof', 'Ffynnon', 'Ddu']
 
say words[0] words[1] words[2]
say
 
-- Dynamic arrays can be simulated via the Java Collections package
splk = ArrayList()
splk.add(words[0])
splk.add(words[1])
splk.add(words[2])
splk.add('Draenen')
 
say splk.get(0) splk.get(3)
say splk.get(0) splk.get(1) splk.get(2)
say
 
-- or by using NetRexx "indexed strings" (associative arrays)
cymru = ''
cymru[0] = 0
cymru[0] = cymru[0] + 1; cymru[cymru[0]] = splk.get(0) splk.get(1) splk.get(2)
cymru[0] = cymru[0] + 1; cymru[cymru[0]] = splk.get(0) splk.get(3)
 
loop x_ = 1 to cymru[0] by 1
  say x_':' cymru[x_]
  end x_