We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Is there a way to set all the values in an array at once with one line of code? I want to make something where if ENTER is pressed then all the values in an array are set to 255.
Thanks
Answers
You would have to use a loop
You can use the fill() method from java.util.Arrays (you will have to import it first).
Here's a short sample code:
import java.util.Arrays; int[] myArray = { 100, 25, 19, 3458 }; void draw() { } void keyPressed() { if (keyCode == ENTER) { int newVal = (int)random(255); println("Filling the array with " + newVal); Arrays.fill(myArray, newVal); // This is what you need printArray(myArray); } }note: printArray() was introduced in Processing 2.1