Array: getLength(Object array) : Array « java.lang.reflect « Java by API






Array: getLength(Object array)

  
/*
 Output:

Array of: int
Array size: 3

 * */

import java.lang.reflect.Array;

public class MainClass {
  public static void main (String args[]) {
    Object array = Array.newInstance(int.class, 3);
    
    Class type = array.getClass();
    if (type.isArray()) {
      Class elementType = type.getComponentType();
      System.out.println("Array of: " + elementType);
      System.out.println("Array size: " + Array.getLength(array));
    }
    
  }
}
           
         
    
  








Related examples in the same category

1.Array: clone()
2.Array: get(Object array, int index)
3.Array: getInt(Object array, int index)
4.Array: newInstance(Class componentType, int length)
5.Array: newInstance(Class componentType, int... dimensions)
6.Array: set(Object array, int index, Object value)
7.Array: setInt(Object array, int index, int i)
8.Array: setLong(Object array, int index, long l)
9.Array: setShort(Object array, int index, short s)