Basic array question
in
Programming Questions
•
1 year ago
What is the cleanest and most efficient way of determining the number of boolean values set to 1 in an array of objects?
I have an array of objects that have a boolean value which determines whether the object (a node) should be displayed to the screen. I want to determine the total number of objects that should be displayed. In other words, all the objects with the boolean variable 'display' equal to 1.
- int total;
- for (int i = 0; i < node.length; i++) {
- if (node[i].display.equals(1)) {
- total++;
- }
- }
Can this be done in one line with an array function rather than using a loop?
1