Describing the example of creating an array (#22366)
* Describing the example of creating an array Describing the example as well as syntax for creating an array * Fixed grammar and formatting issues
This commit is contained in:
committed by
Manish Giri
parent
01097385d6
commit
92b88ea352
@ -37,12 +37,14 @@ Note: The style `double list[]` is not preferred as it comes from the C/C++ lang
|
|||||||
```java
|
```java
|
||||||
dataType[] arrayName = new dataType[arraySize];
|
dataType[] arrayName = new dataType[arraySize];
|
||||||
```
|
```
|
||||||
|
Here we have declared and initialized the array in one step. We could have also written it in two parts with one step being the declaration of array followed by the initialization of array. By default, all memory locations allocated to the array is initialized to its default values, depending upon the datatype.
|
||||||
|
|
||||||
## Code snippets of the above syntax:
|
## Code snippets of the above syntax:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
double[] List = new double[10];
|
double[] List = new double[10];
|
||||||
```
|
```
|
||||||
|
We are creating a array variable named `List` of type double and allocating it 10 memory locations. This double datatype array is initialized to `0.0` by default.
|
||||||
|
|
||||||
## Another way to declare and initialize an Array:
|
## Another way to declare and initialize an Array:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user