Java Array Series – 2 – Declaring and accessing arrays in Java (Images)

Tram Ho

I would like to introduce again how to initialize and access elements in the array.

1. Initialize the array

For example, we initialize an array of ages with 7 elements:

Assign a value to each word:

Or assign at array creation:

Array

2. Access section from any

Syntax example:

The variable a has the value of 9, b has the value of 5.

3. Initialize and access bidirectional arrays

We initialize a two-dimensional array of ages, with the first row of 4 elements , the second row of 4 elements , the third row of 5 elements .

Syntax example:

Initialize first row:

Array ages 1

Initialize the second row:

Array ages 2

Initialize the third array:

Array ages 3

About access syntax:

What is expected of everyone suggestions.

Share the news now

Source : Viblo