previous | start | next

Java Arrays

The array type is not a basic type in Java; it is a class type.

Example declaration

      int[] arr;
   

This declaration does NOT create a array. Like all class type variables, storage for arr is just for a reference.

To create an array object, the new operator is necessary:

      int[] arr; // declares the type of arr
      arr = new int[10]; // creates storage for an array of 10
                         // each gets the default value of int type - 0
      int[] brr;

      brr = arr;  // This only copies the reference, it does NOT
                  // create a new integer array
          
      brr[0] = 10;

      // Now arr[0] is also 10
   


previous | start | next