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)


 
class
	APPLICATION
 
inherit
	ARGUMENTS
 
create
	make
 
feature {NONE} -- Initialization
	make
			-- Run application.
		do
			-- initialize the array, index starts at 1 (not zero) and prefill everything with the letter z
			create my_static_array.make_filled ("z", 1, 50)
 
			my_static_array.put ("a", 1)
			my_static_array.put ("b", 2)
			my_static_array [3] := "c"
 
			-- access to array fields
			print (my_static_array.at(1) + "%N")
			print (my_static_array.at(2) + "%N")
			print (my_static_array [3] + "%N")
 
			-- in Eiffel static arrays can be resized in three ways
			my_static_array.force ("c", 51) -- forces 'c' in position 51 and resizes the array to that size (now 51 places)
			my_static_array.automatic_grow -- adds 50% more indices (having now 76 places)
			my_static_array.grow (100) -- resizes the array to 100 places
		end
 
	my_static_array: ARRAY [STRING]
end
 