JAVA Array Introduction
- An array is nothing but a variable having capability to contain more than one similar types of data items in linear manner.
- Array is also called as linear data structure.
- The length of an array is established when the array is created. After creation, its length is fixed.
- Each item in an array is called an element, and each element is accessed by its numerical index.
- Here array index begins with 0. For example, the 9th element will be accessed at index 8.
- Java supports two types of arrays, such as one-dimensional array and multi-dimensional array.
- The array taking one subscript() is known as one-dimensional array.
- The array taking more than one subscript is known as multi-dimensional array.
// Java program to illustrate creating an array
// of integers, puts some values in the array,
// and prints each value to standard output.
public static void main (String args)
// declares an Array of integers.
// allocating memory for 5 integers.
arr = new int;
// initialize the first elements of the array
arr = 10;
// initialize the second elements of the array
arr = 20;
arr = 30;
arr = 40;
arr = 50;
// accessing the elements of the specified array
for (int i = 0; i < arr.length; i++)
System.out.println("Element at index " + i +
" : "+ arr[i]);
- Array size is fixed.
- Containing homogeneous data items.
- Readymade methods are not supported.