Arrays: Difference between revisions
Content added Content deleted
(1-based index) |
(Add Ecstasy example) |
||
Line 2,978: | Line 2,978: | ||
print f[i] |
print f[i] |
||
.</syntaxhighlight> |
.</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}}== |
=={{header|EGL}}== |