I'd like to set all the values in a boolean array to false without re-initializing it
23,225
Solution 1
Use Arrays.fill
:
Arrays.fill(used, false);
Solution 2
You can just recreate your array, it will be initialized by default to false.
That is when you implement the reset yo can do
used[] = new boolean[26];
Solution 3
Use java.util.Arrays.fill()
:
Arrays.fill(used, false);
Author by
EnkeiRC5
Updated on December 15, 2020Comments
-
EnkeiRC5 over 3 years
public boolean used[] = new boolean[26];
Here is what I have, and it's working great. I know they are all going to be set as false by default. But, as my application is used for a while, some of those are changed to "true". (Which is fine, since that's what my code is supposed to do).
I'm trying to create a "reset" button, which will simulate a reset-like action. Where all variables are restored to what they were when the window was initially created (all drawings go away - just a fresh restart).
And I need all of those true booleans to go back to false in one fell swoop. Any ideas?