Blog

One Dimensional Array in Java | Basic Java Tutorial

One Dimensional Array in Java

Array is a collection of variables of same type which is used by a common name.

A one-dimensional array (or single dimension array) is a type of linear array. Accessing its elements involves a single subscript which can either represent a row or column index.

Program to Demonstrate One dimensional Array in Java

package practice_10;

public class OneDimensionalArray 
{

    public static void main(String[] args)
    {
        int[] myIntegerArray = new int[]{1,2,3,4,5};
//        System.out.println(myIntegerArray[0]);
//        System.out.println(myIntegerArray[1]);
//        System.out.println(myIntegerArray.length);
        for(int i = 0; i<myIntegerArray.length; i++)
        {
            System.out.println(myIntegerArray[i]);
        }
        for(int i: myIntegerArray)
        {
            System.out.println(i);
        }
       
    }
    
}