Java Array Initialization Methods

There are two methods to define arrays in Java.

  1. Use the syntax for static initialization of arrays:
int[] numbers = {1, 2, 3, 4, 5};
String[] names = {"Alice", "Bob", "Charlie"};
  1. Create an array using the new keyword and specify the length:
int[] numbers = new int[5];
String[] names = new String[3];
bannerAds