Java Array Series – 1 – declares arrays in Java

Tram Ho

Arrays in Java arrays are an extremely important object, using a single variable to store multiple values ​​of the same data type.

1. Array declaration (Declaring)

Syntax example:

Including 3 components are:

  • Data types: int (eg String, double, float, …).
  • Variable name: ages.
  • Square brackets: [].

2. Create and initialize arrays (Creating, Initializing).

  • Create (Creating):

    Syntax example:

    The above syntax makes sense to create an array with 10 elements, in other words the ages variable can store 10 values.

  • Initializing:

    Syntax example (1 way):

    The above initialization syntax is meant to initialize 6 elements and have values ​​from 1 – 6. Syntax example (2-way):

    Syntax example (3 dimensional):

3. Access (Accessing).

Syntax example:

4. Example of array:

A piece of code that interacts with an array.

In the Series I will introduce the basic knowledge that I have learned, and based on it to offer problems and how to solve problems.

If anything goes wrong, please comment.

Share the news now

Source : Viblo