Java Array Initialization Methods
There are two methods to define arrays in Java.
- Use the syntax for static initialization of arrays:
int[] numbers = {1, 2, 3, 4, 5};
String[] names = {"Alice", "Bob", "Charlie"};
- Create an array using the new keyword and specify the length:
int[] numbers = new int[5];
String[] names = new String[3];