In Java, you can create an array of integers using the new
operator and the int
data type. Here is an example:
int[] arr = new int[5];
This creates an array of integers with a length of 5. The elements of the array are initialized to their default values (0 for integers).
You can also initialize the elements of the array with specific values using array initialization syntax:
int[] arr = {1, 2, 3, 4, 5};
You can access the elements of the array using the index of the element, starting at 0 for the first element. For example:
int[] arr = {1, 2, 3, 4, 5}; int first = arr[0]; // first is 1 int last = arr[4]; // last is 5
For more information on arrays in Java, you can refer to the Java documentation.