TreeNode[] children = grid[row][col].getChildren();
我想要一个简单的函数来告诉我这个数组中有多少个对象? getChildren()
将返回一个大小不大于4的对象,例如:
children[0] = null;
children[1] = TreeNode Object
children[2] = null;
children[3] = null;
最佳答案
你为什么不自己写:
public static <T> int getLength(T[] arr){
int count = 0;
for(T el : arr)
if (el != null)
++count;
return count;
}
关于java - 像 array.length 这样不包含 NULL 元素的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7466102/