What is the method for defining arrays in Java?

There are two ways to define an array in Java.

  1. Defining an array using array literal, for example:
int[] numbers = {1, 2, 3, 4, 5};
String[] names = {"Alice", "Bob", "Carol"};
  1. 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];
Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds