Java Array.getLength(Object array)

Syntax

Array.getLength(Object array) has the following syntax.

public static int getLength(Object array)   throws IllegalArgumentException

Example

In the following code shows how to use Array.getLength(Object array) method.


import java.lang.reflect.Array;
import java.util.Arrays;
//  ww w .  j a v  a2  s.co m
public class Main{
  public static void main(String[] args) {
    int[] sourceInts = { 12, 78 };
    int[] destInts = new int[2];
  
    for (int i = 0; i < Array.getLength(sourceInts); i++) {
      Array.set(destInts, i, Array.get(sourceInts, i));
      System.out.println(Array.get(destInts, i));
    }
    System.out.println(Arrays.toString(destInts));
  } 
}

The output:





















Home »
  Java Tutorial »
    java.lang.reflect »




Array
Constructor
Field
Method
Modifier
ParameterizedType
TypeVariable