Return the length of the specified array for Object arrays and with primitive arrays in Java
Description
The following code shows how to return the length of the specified array for Object arrays and with primitive arrays.
Example
/*from w w w .j a v a2 s . com*/
import java.lang.reflect.Array;
public class Main {
public static void main(String[] argv) {
double[] data = new double[] { 1.2 };
System.out.println(data);
}
public static int getLength(Object array) {
if (array == null) {
return 0;
}
return Array.getLength(array);
}
}
The code above generates the following result.