【发布时间】:2011-06-11 09:59:07
【问题描述】:
我想检测数组的子范围是否包含空引用。有点像这样:
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;
}
Java 库中是否有这样的方法,所以我不必手动循环遍历数组?也许我已经被 C++ 对专注于算法的代码的出色支持宠坏了,我可以在这里写:
#include <algorithm>
bool found_null = (std::find(array + from, array + to, 0) != array + to);
【问题讨论】:
-
我担心您必须将帖子中的代码复制到您的代码库中!
-
如果您对图书馆的更多优点感兴趣,(除了 apache common-lang)请查看 guava,其中包括 google 的收藏库。
标签: java c++ arrays algorithm null