View RSS Feed

Initialize

Initialize array

  1. Array Initializers

    by , 03-04-2012 at 10:14 AM
    In a declaration, an array initialize might be specified. It also might be specified as an array creation expression part, that gives certain initial values and creates an array.

    ArrayInitializer:
    { VariableInitializersopt ,opt }

    VariableInitializers:
    VariableInitializer
    VariableInitializers , VariableInitializer

    To make it further clear:

    VariableInitializer:
    Expression
    ArrayInitializer
    ...
    Categories
    Initialize
  2. Creating, Initializing, and Accessing an Array

    by , 03-04-2012 at 10:05 AM
    One can create an array by the help of the new operator. In ArrayDemo program, next statement allocates the array along with quite enough memory. This is done for 10 integer elements so that to assign array to anArray variable.

    Java Code:
    // create an array of integers
    anArray = new int[10];
    In case if the given statement is missing, an error like this would be printed by compiler and also the compilation would fail.


    To array’s each element, ...