Creating an Array - Java Language Basics

Java examples for Language Basics:Array

Description

Creating an Array

Demo Code

import java.lang.reflect.Array;

public class Main {
  public void main(String[] argv) {
    // An array of 10 ints.
    int[] ints = (int[]) Array.newInstance(int.class, 10);

    // An array of 10 int-arrays.
    int[][] ints2 = (int[][]) Array.newInstance(int[].class, 10);

    // A 10x20 2-dimenional int array.
    ints2 = (int[][]) Array.newInstance(int.class, new int[] { 10, 20 });
  }/*from  www  .  ja  v a2s .c  om*/
}

Related Tutorials