elibraryportal Logo

Array in Java

→ Array is a collection of similar type of elements that have contiguous memory location.

→ It is an object the contains elements of similar data type.

→ Its index start from 0.

Array in Java

Advantages

  • Code optimization: We can retrieve or sort the data easily.
  • Random Access: We can get any data located at any index position.
  • Type safe

Disadvantages

  • Size Limit: We can store only fixed size of elements in the array. It doesn't grow its size at runtime.

Types of Array in java

There are 2 types of array.

  • Single Dimensional Array
  • Multidimensional Array

Single Dimensional Array in java

Syntax

Single Dimensional Java Array

Where we are going to declare, instantiate, initialize and traverse an array.

Declaration, Instantiation and Initialization in array

Example

Multidimensional array in java

Data is stored in row and column based index (also known as matrix form).

Syntax

Example

Output

       2 6 8
       6 8 10