In this tutorial we will see how can we print an array in java . For this we have written two codes.
class HindiCodingCommunity {
public static void main(String[] args) {
int[] array = {1, 2, 3, 4, 5};
for (int i=0;i<array.length;i++) {
System.out.println(array[i]);
}
}
}
In this we have created the variable i and accessing all the elements of the array one by one and printing them.
class HindiCodingCommunity {
public static void main(String[] args) {
int[] array = {1, 2, 3, 4, 5};
for (int i: array) {
System.out.println(i);
}
}
}