Java Arrays: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 13: Line 13:
<span id='Array_Component'></span>An array instance contains a number of variables, called '''array components'''. The array components have no names, and they are referenced by array access expressions that use non-negative integer indices. The number of components is fixed, once the array instance is created, the number of components cannot change.  
<span id='Array_Component'></span>An array instance contains a number of variables, called '''array components'''. The array components have no names, and they are referenced by array access expressions that use non-negative integer indices. The number of components is fixed, once the array instance is created, the number of components cannot change.  


The components can be of [[Java_Language#Primitive_Types|primitive types]] or [[Java_Language#Reference_Types|reference types]]. Multidimensional arrays are a special case where all the components have the same [[#Array_Type|array type]], which is one of the reference types.
The components can be of [[Java_Language#Primitive_Types|primitive types]] or [[Java_Language#Reference_Types|reference types]]. Multidimensional arrays are a special case where all the components have the same [[#Array_Type|array type]], which is in itself a reference types. More details about array types are available in the [[#Array_Types|Array Types]] section below.


If the number of components of an array is zero, the array is said to be empty. If the array has n components, then it is said that the array has the length n. In this case, its components are referenced with zero-based indices from 0 to n-1.
If the number of components of an array is zero, the array is said to be empty. If the array has n components, then it is said that the array has the length n. In this case, its components are referenced with zero-based indices from 0 to n-1.

Revision as of 00:55, 2 November 2021

External

Internal

Overview

Array instances are objects. They are dynamically created, they can be assigned to a variable of type Object and all methods of class Object may be invoked on an array.

An array instance contains a number of variables, called array components. The array components have no names, and they are referenced by array access expressions that use non-negative integer indices. The number of components is fixed, once the array instance is created, the number of components cannot change.

The components can be of primitive types or reference types. Multidimensional arrays are a special case where all the components have the same array type, which is in itself a reference types. More details about array types are available in the Array Types section below.

If the number of components of an array is zero, the array is said to be empty. If the array has n components, then it is said that the array has the length n. In this case, its components are referenced with zero-based indices from 0 to n-1.


array element

Array Types

An array type is a case of a reference type.

Array Variables

Array Creation

Array Creation with an Expression

Array Creation with an Array Initializer

Array Access

Multidimensional Arrays

A multidimensional array is an array of multidimensional arrays.

Bidimensional Arrays

Tridimensional Arrays