What is the method for defining arrays in Java?
There are two ways to define an array in Java.
- Defining an array using array literal, for example:
int[] numbers = {1, 2, 3, 4, 5};
String[] names = {"Alice", "Bob", "Carol"};
- Create an array using the “new” keyword and specify the size of the array, for example:
int[] numbers = new int[5];
String[] names = new String[3];