java arrays tutorial

Bodhak java arrays beginners tutorial in this chapter we will cover in detail about the single dim array, Working with a double dim array, Working with the jagged array with syntaxes and example programs.

An array, in the context of Java, is a dynamically created object that serves as a container to hold a constant number of values of the same type. By declaring an array, memory space is allocated for values of a particular type. At the time of creation, the length of the array must be specified and remains constant.

 

 

java arrays beginners tutorial

An array is an object.

An array variable does not actually store the array – it is a reference variable that points to an array object.

Declaring the array variable does not create an array object instance; it merely creates the reference variable – the array object must be instantiated separately.

Once instantiated, the array object contains a block of memory locations for the individual elements.

Once instantiated, the array object contains a block of memory locations for the individual elements.

If the individual elements are not explicitly initialized, they will be set to zero.

Arrays can be created with a size that is determined dynamically (but once created, the size is fixed).

To access an array element, the numerical index (a nonnegative value) corresponding to the location of that element must be used. Index starts with 0(zero).

An array element that is also an array is known as a sub-array.

 

Advantages of Arrays:

The array is used to represent multiple data items of the same type by using the only single name.

The array can be used to implement other data structures like linked lists, stacks, queues, trees, graphs etc.

This allows random accessing of elements i.e. any element of the array can be randomly accessed using indexes.

It allows random accessing of elements i.e. any element of the array can be randomly accessed using indexes.

The array is capable of storing many elements at a time

Types of arrays supported by Java:

the single dimensional array

Double dimensional array (or) multidimensional array

jagged array