Jump to content

Creating an Array: Difference between revisions

Line 349:
 
=={{header|Groovy}}==
In Groovy "arrays" are synonymous with "lists", and are thus not of a fixed size. Ranges are also a type of list.
<lang groovy>
myArray1 = [] // empty list (content may be added as desired)
myArray = []
myArray2 = [1, 2, 3] // 3-element (for now) list containing first 3 integers
myArray3 = 1..3 // the same 3-element list expressed as a range.
// ranges themselves are immutable, but can be used as operands whereever a list is expected
myArray4 = ["xx"]*20 // 20-element (for now) list, each element of which is currently the string "xx"
</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.