Creating Arrays
Creating Arrays
Create arrays similarly to variables, but with a little extra.
Two ways in Processing…
Using the new keyword and square brackets [ ]
Using square [ ] and curly { } brackets
Method 1: The new Keyword
The new keyword is used to tell the program there will be a new specific type of data .
Square brackets [ ] are placed right after the data type for all the elements of an array .
The number of elements (if known) should be listed within the type following the new keyword .
Then, assign each element individually.
Examples:
Processing:
Method 2: Using Brackets and Initial Values
Arrays can be created with initial values listed all at once within curly brackets { } .
Square brackets [ ] are placed right after the data type for all the elements of an array to signify it as an array.
Examples:
Processing:
Last updated
Was this helpful?