Arrays: Difference between revisions

Add Ecstasy example
(1-based index)
(Add Ecstasy example)
Line 2,978:
print f[i]
.</syntaxhighlight>
 
=={{header|Ecstasy}}==
Arrays use the [] syntax from C, use zero-based indexing, have a literal syntax, and are implemented by the [https://github.com/xtclang/xvm/blob/master/lib_ecstasy/src/main/x/ecstasy/collections/Array.x Array] class.
<syntaxhighlight lang="java">Int[] literalArray = [1,2,3];
Int[] fixedLengthArray = new Int[10];
Int[] variableArray = new Int[];
 
assert literalArray.size == 3; // array size
Int n = literalArray[2]; // array access
fixedLengthArray[4] = 12345; // replace value at index
 
fixedLengthArray += 6789; // "add" a value (creates an array copy)
variableArray += 6789; // "add" a value (efficient append)</syntaxhighlight>
 
=={{header|EGL}}==
162

edits