Get array length

 
import java.lang.reflect.Array;

public class SampleGetArrayReflection {

  public static void main(String[] args) {
    int[] sourceInts = { 12, 78 };
    int[] destInts = new int[2];
    copyArray(sourceInts, destInts);
    String[] sourceStrgs = { "Hello ", "there ", "everybody" };
    String[] destStrgs = new String[3];
    copyArray(sourceStrgs, destStrgs);
  }

  public static void copyArray(Object source, Object dest) {
    for (int i = 0; i < Array.getLength(source); i++) {
      Array.set(dest, i, Array.get(source, i));
      System.out.println(Array.get(dest, i));
    }
  }
}
  
Home 
  Java Book 
    Runnable examples  

Reflection Array:
  1. Create an array of 10 ints.
  2. Create a 10x20 2-dimensional int array
  3. Fill and display an array
  4. Get and Set the Value of an Element in an Array Object
  5. Get array(component) type
  6. Get array dimensions
  7. Get array length
  8. Get array name and type
  9. Is an Object an Array