I have an array
of boolean
entries:
boolean[] myBooleanArray = new boolean[24];
Currently i check if it contains true like so:
Arrays.asList(myBooleanArray).contains(true);
Is this the fastest way to check an array of boolean? If not, what is the fastest way to perform this check?
EDIT:
I timed the methods in your answers as follows by running it as an app on an Android 4.03 Samsung S2 device:
boolean[] myBooleanArray = new boolean[24];
long startTime = System.nanoTime();
suggestedMethod(myBooleanArray);
long endTime = System.nanoTime();
long duration = endTime - startTime;
Log.i("timetest", Long.toString(duration));
Time ranking over five runs were, with fastest first:
Between 5334 and 11584 ns:
for (boolean value : myBooleanArray) { if (value) { return true; } } return false;
Between 160542 and 171417 ns:
Arrays.asList(myBooleanArray).contains(true);
Between 191833 and 205750 ns:
Booleans.contains(myBooleanArray, true);