How is an array defined in Java?
In Java, arrays can be defined using the following syntax:
- Declare an array type and name it as follows: int[] numbers;
- Create an array and specify its length using the ‘new’ keyword: numbers = new int[5];
- Initialize the array element: numbers[0] = 1;
- Another way to define and initialize an array is by using the simplified method: int[] numbers = {1, 2, 3, 4, 5};