Professional Documents
Culture Documents
Lesson 2: Array: DCIT 50 - Object Oriented Programming Prepared By: Marie Joy Ignacio
Lesson 2: Array: DCIT 50 - Object Oriented Programming Prepared By: Marie Joy Ignacio
ARRAY
DCIT 50 – Object Oriented Programming
Prepared by: Marie Joy Ignacio
▪An array is a
container object
that holds a fixed
number of values
of a single type.
•Code Optimization: It
makes the code
optimized, we can
ADVANTAG retrieve or sort the data
efficiently.
ES:
•Random access: We can
get any data located at an
index position.
▪ Size Limit: We can store only
the fixed size of elements in the
DISADVAN
array. TAGE:
HOW TO DECLARE ARRAY IN
JAVA
Data Type
Array Name
HOW MANY ELEMENTS CAN
ARRAY THIS HOLD?
▪ For example: ▪ Example of an array in single statement
HOW TO ACCESS ELEMENTS
OF AN ARRAY IN JAVA?
EXAMPL
E: ARRAY
ACCESS
ELEMEN
TS
JAVA ARRAY INITIALIZATION
12 4 5 2 5
OUTPUT:
LOOPING THROUGH ARRAY
ELEMENTS
▪ Example: Using for Loop
OUTPUT:
class Testarray{
public static void main(String args[]){
int a[]=new int[5];
a[0]=10;
a[1]=20;
EXAMPLE a[2]=70;
a[3]=40;
2: a[4]=50;