Default Value of Elements in an Integer Array in Java SE 22

In Java, the default value of elements in an integer array (or any other array of primitive types) is determined by the default value of the element type. For integers, the default value is 0.

So, if you create an integer array without initializing its elements explicitly, all elements will be set to 0. Here’s an example:

public class Main {
public static void main(String[] args) {
int[] array = new int[5]; // Creating an integer array of size 5
// Elements are initialized to 0 by default
for (int i = 0; i < array.length; i++) {
System.out.println("Element " + i + ": " + array[i]);
}
}
}

Output:

Element 0: 0
Element 1: 0
Element 2: 0
Element 3: 0
Element 4: 0

This behavior holds true for Java SE 22 as well as earlier versions of Java.