I have a big array of booleans and i need just to work with the true elements, and need theyer index.
for (int x = 0; x < cells.length; x++) {
for (int y = 0; y < cells[0].length; y++) {
if (cells[x][y]) {
g.fillRect(x * cellSize, y * cellSize, cellSize, cellSize);
}
}
}
so how can i do that without the two foor loops and save the time?
I'd say this is the best you can get.
You are already using a primitive array and I expect primitive boolean type.
The only thing I could suggest is saving cells.length and cells[0].length in final variables before the loops, it could save some time, but the compiler may already optimize this on its own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With