0% found this document useful (0 votes)
9 views9 pages

Array in Java

An array in Java is a data structure that stores multiple values of the same data type in contiguous memory locations, accessed via an index. Key features include fixed-size elements, uniform data types, zero-based indexing, and random access. The document also covers array declaration, initialization, and introduces two-dimensional arrays for matrix-like data storage.

Uploaded by

Kamalesh
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)
9 views9 pages

Array in Java

An array in Java is a data structure that stores multiple values of the same data type in contiguous memory locations, accessed via an index. Key features include fixed-size elements, uniform data types, zero-based indexing, and random access. The document also covers array declaration, initialization, and introduces two-dimensional arrays for matrix-like data storage.

Uploaded by

Kamalesh
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

Array in Java

An array in Java is a data structure used to store multiple values of the same
data type in a single variable. The values are stored in contiguous memory
locations and are accessed using an index.

Key Features of Arrays

 Stores fixed-size elements


 All elements must be of the same data type
 Index starts from 0
 Allows random access to elements

Declaring an Array
dataType[] arrayName;

or

dataType arrayName[];

Example:
int[] marks;

Creating an Array
marks = new int[5];

This creates an array that can store 5 integers.

Declaring and Initializing an Array in Java


Method 1: Declaration and Initialization in Separate Steps

Method 2: Declaration and Initialization in a Single Line


Java Program: Sum and Average of 5 Numbers Using Array
Java Program: Sum and Average of n Numbers Using Array
Two-Dimensional Array in Java

A two-dimensional (2D) array in Java is an array of arrays. It is used to store data


in rows and columns, similar to a table or matrix.
Java Program: Matrix Addition (3 × 3)

You might also like