From 1a74d0f114738628c5ac0d021599ce9027613a4b Mon Sep 17 00:00:00 2001 From: BoopMehNose <33704699+BoopMehNose@users.noreply.github.com> Date: Wed, 23 Jan 2019 14:17:32 -0500 Subject: [PATCH] Changes to creating arrays and array section (#33800) Clarification and exemplification in the #Array section and expands the example in the ##Creating Arrays section. --- guide/english/java/arrays/index.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/guide/english/java/arrays/index.md b/guide/english/java/arrays/index.md index e8b7160216..d4ff3e5d13 100644 --- a/guide/english/java/arrays/index.md +++ b/guide/english/java/arrays/index.md @@ -5,8 +5,8 @@ title: Arrays # Array An Array is a collection of values (or objects) of similar datatypes (both primitive and reference datatypes are allowed) held in sequential memory addresses. -All the variables in the array must be of the same type, declared at instantiation. -Arrays always start with an index of 0 and are instantiated to a set number of indexes. +All the variables in the array must be of the same type, declared at instantiation. Failure to remain consistent with the type will lead to compilation errors. +Arrays always start with an index of 0 and are instantiated to a set number of indexes. To clarify, an array that is instantiated will be created to hold a certain number of variables. The number of variables that can be held in an array is not mutable. **Syntax:** @@ -36,7 +36,13 @@ Note: The style `double list[]` is not preferred as it comes from the C/C++ lang ## Creating Arrays: ```java -dataType[] arrayName = new dataType[arraySize]; +dataType[] arrayName = new dataType[arraySize]; //Preferable +``` + +OR + +```java +datatype arrayName[] = new dataType[arraySize]; //Not preferable ``` 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.