Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 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