Introduction
In Java, an array is a collection of variables with similar types referred to by a common name. Let’s start by recalling some of the essential points about Java arrays.
- Arrays are objects in Java and are allocated dynamically. We can use the object property length to determine its length.
- A Java array variable can also be declared in the same way that other variables are, by appending [] after the data type.
- The array's variables are ordered, and each has an index starting at 0.
- Java arrays can also be used as static fields, local variables, and method parameters.
- An array's size must be specified as an int or short value, not a long value.
In this article, we’ll learn how to print elements of an array one by one. So, let’s get started!
Problem Statement
Write a Java program to print the elements of an array one by one.
Example: Let the array given by:
Arr = 1,2,3,4,5
Output: 1 2 3 4 5
In this problem, we must create an array and print the array's elements. In the example above, 1, 2, 3, 4 and 5 represent the elements of the array. These elements are accessible via their corresponding indexes, which are 0, 1, 2, 3, and 4.
Must Read Array of Objects in Java