Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

2D-array

An array in Java is a collection of similar data types stored in contiguous memory locations, with fixed size, indexed access, and homogeneous elements. Arrays can be defined through separate declaration and initialization or together. A 2D array is an array of arrays, used to represent data in a tabular form, and can also be declared and initialized similarly.

Uploaded by

galandedikasha03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

2D-array

An array in Java is a collection of similar data types stored in contiguous memory locations, with fixed size, indexed access, and homogeneous elements. Arrays can be defined through separate declaration and initialization or together. A 2D array is an array of arrays, used to represent data in a tabular form, and can also be declared and initialized similarly.

Uploaded by

galandedikasha03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1. Define Array.

An array in Java is a collection of similar data types stored in contiguous memory locations.
It is used to store multiple values in a single variable, instead of declaring separate variables for each
value.

Important Properties of Arrays:

1. Fixed Size: Once an array is created, its size cannot be changed.

2. Indexed: Array elements are accessed using indices (starting from 0).

3. Homogeneous: All elements in an array must be of the same data type.

4. Stored in Contiguous Memory: Elements are stored one after another in memory.

5. Length Property: array.length gives the size of the array.

6. Random Access: You can directly access any element using its index

2. Two Different Ways to Define an Array:

Method 1: Declaration + Initialization Separately

int[] numbers; // Declare

numbers = new int[5]; // Allocate memory for 5 integers

Method 2: Declaration + Initialization Together

int[] numbers = {10, 20, 30, 40, 50};

3. Define 2D Array.

A 2D array is an array of arrays — also called a matrix or table, with rows and columns.
It is used to represent data in tabular form.

Declaration of a 2D Array:

int[][] matrix = new int[3][4]; // 3 rows and 4 columns

You can also define it with initialization:

int[][] matrix = {

{1, 2, 3},

{4, 5, 6},

{7, 8, 9}

};

You might also like