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

Presentation 1

This document discusses arrays in Java, including what arrays are, the need for arrays, how to access array elements, display arrays, get the length and index of an array, create multi-dimensional arrays, and reverse an array. Arrays are collections of similar data types that store elements in contiguous memory blocks, allowing faster access than individual variables. The document covers array declaration, initialization, accessing elements, looping through arrays, and a method to reverse the elements of an array.

Uploaded by

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

Presentation 1

This document discusses arrays in Java, including what arrays are, the need for arrays, how to access array elements, display arrays, get the length and index of an array, create multi-dimensional arrays, and reverse an array. Arrays are collections of similar data types that store elements in contiguous memory blocks, allowing faster access than individual variables. The document covers array declaration, initialization, accessing elements, looping through arrays, and a method to reverse the elements of an array.

Uploaded by

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

C O N T E N T:

• What is ARRAY…?
• Need of ARRAY
• Accessing ARRAY
Elements
• Displaying ARRAY
• Length & index of AR RAY [ ]
ARRAY
• Multi-dimensional
ARRAY
• Reversing The
ARRAY

created by:
RITESH DEV
WHAT IS ARRAY…?
 Array is a collection of similar types of data.
 An array is a container object that holds a
fixed number of values of a single type.
 The length of an array is established when
the array is created.
 After creation, its length is fixed.
NEED OF ARRAY…
 With a var. reference, a object is created.
 Elements r stored in contiguous memory
blocks.
 Accessing elements in an Array is faster.
ACCESSING ARRAY ELEMENT(S)

DECLARATION + MEMORY ALLOCATION

DECLARATION + MEMORY ALLOCATION


+ INITIALIZATION
Syntax for
DECLARATION + MEMORY ALLOCATION

int [] Arr= new int [3];


Arr [0]= 7;
Arr [1]= 9;
Arr [2]= 6;
Arr [3]= 7;
Arr [4]= 9;
Syntax for
DECLARATION + MEMORY ALLOCATION + INITIALIZATION

int [] Arr= {2, 4, 8, 12, 16};


LENGTH & INDEX OF ARRAY w

 Array has length property which gives the


length of the Array.
 Length = no. of elements stored in it.
 SYNTAX: (Arr_name.length);

 Array Index starts from 0, & goes till (n-1)


where n is the length of the Array.
DISPLAYING ARRAY…

for loop:
SYNTAX:
for(int a=0; a<Arr.length; a++){
sysout(Arr[a]);}

for-each loop:

SYNTAX:
for(int e: Arr){
sysout(e);}
MULTI-DIMENSIONAL ARRAY -

 Multi-Dimensional Arrays are Array of Arrays.


 Each element of a Multi-Dimensional Array is
an array itself.
 Example here is 2-Dimensional Array.

SYNTAX:
int [][] Arr= new int [9][3];
REVERSING THE ARRAY-

SYNTAX:
int temp; int l= arr.length/2;
for(int a= 0; a<l; a++){
temp= arr[a];
arr[a]= arr[arr.length-1-a];
arr[arr.length-a-1]= temp;}
THANK U...!!!
For ur attention

GOAL OF THIS PRESENTAION IS TO


STRONG THE CONCEPT OF ARRAY[] IN
JAVA…

You might also like