From 656202755a3193e94f4723f4e139f63a080d234c Mon Sep 17 00:00:00 2001 From: jamiesteck Date: Mon, 21 Jan 2019 07:28:13 -0800 Subject: [PATCH] Update index.md and provide additional examples (#28758) I added several additional examples of how to create and access an array. --- guide/english/java/arrays/index.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/guide/english/java/arrays/index.md b/guide/english/java/arrays/index.md index ce199b1654d..13939bfc6c0 100644 --- a/guide/english/java/arrays/index.md +++ b/guide/english/java/arrays/index.md @@ -43,6 +43,8 @@ Here we have declared and initialized the array in one step. We could have also ```java double[] List = new double[10]; +String[] words = new String[20]; +int[] numbers = new int[100]; ``` 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. @@ -61,6 +63,11 @@ The code above is equivalent to: double[] list = new double[4]; *IMPORTANT NOTE: Please note the difference between the types of brackets that are used to represent arrays in two different ways. + +String[] rainbow = {"red", "orange", "yellow", "green", "blue", "purple"}; + +The code above is equivalent to: +String[] rainbow = new String[6]; ``` ## Declaring array literal @@ -92,6 +99,8 @@ Output: ## Modifying Arrays: ```java arrayName[index] = value; + +rainbow[0] = "red"; ``` Note: You cannot change the size or type of an array after initializing it.