public class Test1 { public static void main(String[] args) { int[] arr = {1, 2, 3}; System.out.println(arr.length); System.out.println(java.lang.reflect.Array.getLength(arr)); } }getLength 方法确实有,但那是一个静态的本机方法,应该不是让开发者拿来用的。当它不存在可能更好些。
public static int getLength(Object array) throws IllegalArgumentException Returns the length of the specified array object, as an int. Parameters: array - the array Returns: the length of the array
public static int getLength(Object array) throws IllegalArgumentException Returns the length of the specified array object, as an int. Parameters: array - the array Returns: the length of the array
length是数组的属性
length()是String类型的方法
“getlength()和length 两者都是获得数组的长度”???数组是通过length属性得到长度的
具体对象是通过length()方法得到长度的,也有使用getlength()方法的(如果可以得到长度)好像暂没见过同时通过 getlength()和length 访问长度的
数组当然没有getlength()方法了,地球人都知道滴不过有的类是有getLength()方法滴是不是大家都误解了
你当初还不是有这个那个问题的啊
我也查过api确实没有getlength这个属性
public static void main(String[] args) {
int[] arr = {1, 2, 3};
System.out.println(arr.length);
System.out.println(java.lang.reflect.Array.getLength(arr));
}
}getLength 方法确实有,但那是一个静态的本机方法,应该不是让开发者拿来用的。当它不存在可能更好些。
throws IllegalArgumentException
Returns the length of the specified array object, as an int. Parameters:
array - the array
Returns:
the length of the array
throws IllegalArgumentException
Returns the length of the specified array object, as an int. Parameters:
array - the array
Returns:
the length of the array