I want to detect whether or not a subrange of an array contains the null reference. Somehow like this:
public static <T> boolean containsNull
(T[] array, int fromInclusive, int toExclusive)
{
for (int i = fromInclusive; i < toExclusive; ++i)
{
if (array[i] == null) return true;
}
return false;
}
Is there a method like this in the Java library so I don't have to manually loop over the array? Maybe I have been spoiled by C++'s excellent support for algorithmically focused code, where I can just write:
#include <algorithm>
bool found_null = (std::find(array + from, array + to, 0) != array + to);