top of page
Search
Writer's pictureSiah Peih Wee

Using Array in Java



Firstly, to understand Array, you can visualise it as a BOX with multiple compartments, like a Pill Box.



Next, you will learn how write codes to use Array. Below is example of an Array storing a list of characters.

char[] aAlphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G'};

The first item's id in the Array is ZERO.

System.out.println("Accessing first item " + aAlphabet[0]); 

Below is an example, you can see of how an Array is declared and accessed. To view the console's print line, you will need to click "Open on Replit"

You may want to read more


You can also declare an Array with the size/length without data. Below is an example of how you can fill the array during runtime. To view the console's print line, you will need to click "Open on Replit"


22 views0 comments

Comments


Post: Blog2 Post
bottom of page