Home >>Java Programs >Java Program to print the elements of an array
In this example, we will see a java program to create an array and then print it's all elements.
An Array is a special variable that stores multiple values under the same name in the contiguous memory allocation. Elements of an array can be accessed through their indexes.
Program:
public class Main
{
public static void main(String[] args)
{
int [] arr = new int [] {1, 2, 3, 4, 5, 6, 7, 8, 9};
System.out.println("Elements of given array: ");
for (int i = 0; i < arr.length; i++)
{
System.out.print(arr[i] + " ");
}
}
}