Simple array Example Java Program

Definition

An array is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. An array is stored so that the position of each element can be computed from its index by a mathematical formula. The simplest type of data structure is a linear array, also called one-dimensional array.

Syntax

Data_type[] Variable_name = new Data_type[Length];

Simple array Example Program

class SimpleArray{  
	public static void main(String args[]){
		int[] a=new int[5];
		a[0]=5;  
		a[1]=10;  
		a[2]=15;  
		a[3]=20;  
		a[4]=25;   
		for(int i=0;i < a.length;i++){
			System.out.println(a[i]);  
		}
	}
}

Sample Output

Output is:
5
10
15
20
25