how to decleare an array in java

how to decleare an array in java

In Java, you can declare an array by using the new operator and the array type.

The array type is specified by the element type followed by square brackets []. For example, int[] is an array of integers, String[] is an array of strings, and Object[] is an array of objects.

To declare an array, you can use the following syntax:

r‮:ot refe‬lautturi.com
elementType[] arrayName = new elementType[arraySize];

Here, elementType is the type of the elements in the array, arrayName is the name of the array, and arraySize is the number of elements in the array.

For example, to declare an array of integers with 10 elements, you can use the following code:

int[] numbers = new int[10];

This creates an array of integers with 10 elements, all of which are initialized to their default value (0 for integers).

You can also use the following syntax to declare and initialize an array in one line:

elementType[] arrayName = { element1, element2, ... };
Created Time:2017-11-01 20:42:49  Author:lautturi