Initializing the elements of an array with an array initializer. - Java Language Basics

Java examples for Language Basics:Array

Description

Initializing the elements of an array with an array initializer.

Demo Code

public class Main 
{
   public static void main(String[] args)
   {/*from  w  w w.ja v a 2s .  com*/
      // initializer list specifies the initial value for each element
      int[] array = {132, 217, 614, 118, 915, 14, 910, 701, 60, 37};

      System.out.printf("%s%8s%n", "Index", "Value"); // column headings
   
      // output each array element's value 
      for (int counter = 0; counter < array.length; counter++)
         System.out.printf("%5d%8d%n", counter, array[counter]);
   }
}

Result


Related Tutorials