Files
processing4/web/reference/API/Array.xml
2005-01-27 06:48:42 +00:00

94 lines
2.0 KiB
XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<name>Array</name>
<category>Data</category>
<subcategory>Composite</subcategory>
<usage>Web &amp; Application</usage>
<example>
<image></image>
<code>
int[] numbers = new int[3];
numbers[0] = 90;
numbers[1] = 150;
numbers[2] = 30;
int a = numbers[0] + numbers[1]; // Sets variable a to 240
int b = numbers[1] + numbers[2]; // Sets variable b to 180
</code>
</example>
<example>
<image></image>
<code>
int[] numbers = { 90, 150, 30 };
int a = numbers[0] + numbers[1]; // Sets variable a to 240
int b = numbers[1] + numbers[2]; // Sets variable b to 180
</code>
</example>
<example>
<image></image>
<code>
int degrees = 360;
float[] cos_vals = new float[degrees];
for(int i=0; i &lt; degrees; i++) {
cos_vals[i] = cos(TWO_PI/degrees * i);
}
</code>
</example>
<description>
An array is a list of data. It is possible to have an array of any type of data. Each piece of data in an array is identified by an index number representing its position in the array. The first element in the array is <b>[0]</b>, the second element is <b>[1]</b>, and so on. Arrays are similar to objects, so they must be created with the keyword <b>new</b>. Every array has a variable <b>length</b> which is an integer value for the total number of elements in the array.
</description>
<syntax>
<c>datatype</c>[] <c>var</c>
<c>var</c>[<c>element</c>] = <c>value</c>
<c>var</c>.length
</syntax>
<parameter>
<label>datatype</label>
<description>any primitive or compound datatype, including user defined classes</description>
</parameter>
<parameter>
<label>var</label>
<description>any valid variable name</description>
</parameter>
<parameter>
<label>element</label>
<description>int: must not exceed the length of the array - 1</description>
</parameter>
<parameter>
<label>value</label>
<description>data to assign to the array element, must be the same datatype as the array</description>
</parameter>
<returns></returns>
<related></related>
<availability>1.0</availability>
<type>Object</type>
<partof>PDE</partof>
</root>