Assigning Values to an Array: Difference between revisions
Content added Content deleted
Line 183: | Line 183: | ||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
<lang groovy>def array = [0]*3 // three elements all initialized to zero |
|||
println array |
|||
array[1] = 1 |
|||
println array |
|||
def strings = ['Mary', 'had', 'a', 'little', 'lamb', ". It's", 'fleece', 'was', 'white', 'as', 'snow'] |
|||
println strings |
|||
strings[0] = 'Arthur' |
|||
strings[4] = 'towel' |
|||
strings[6] = 'stain' |
|||
strings[8] = 'ripe' |
|||
strings[10] = 'strawberries' |
|||
println strings</lang> |
|||
Output: |
|||
<pre>[0, 0, 0] |
|||
[0, 1, 0] |
|||
["Mary", "had", "a", "little", "lamb", ". It's", "fleece", "was", "white", "as", "snow"] |
|||
["Arthur", "had", "a", "little", "towel", ". It's", "stain", "was", "ripe", "as", "strawberries"] |
|||
</pre> |
|||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
{{works with|GHC| 6.6}} |
{{works with|GHC| 6.6}} |