Get the length of an Array

Get the length of an Array

ReturnMethodSummary
static intgetLength(Object array)Returns the length of the specified array object, as an int.

import java.lang.reflect.Array;
import java.util.Arrays;

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:


12
78
[12, 78]
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.