COMPUTER PROGRAMMING 1
Java Arrays
CC 102 - Module 7
GEMMARIE T. MUÑOZ
Java Arrays
01
02
03
04
is a collection of multiple values in a
Single Variable with the Same Datatype
they are governed by using an index.
Are the individuals in an array.
Is a number that represents
a position in a collection.
DECLARE WITH VALUES
Syntax:
datatype identifier[] = {value1, value2, value3, value4};
Sample:
String names[] = {“Rodel”, “Ranier”, “Kurt”, “Princess”};
*This creates an array with the specified values.
DECLARE WITHOUT VALUES
Syntax:
datatype identifier[] = new datatype[size];
Sample:
int numbers[] = new int[5];
*This creates an array of size 5 with default values (0 in this case)
This is to find out how many
elements an array has,
use the length property.
[Link]([Link]);
READING ARRAY ELEMENT
Syntax:
identifier [index];
Sample:
Names[0];
MODIFYING ARRAY ELEMENT
Syntax:
identifier[index] = value;
Sample:
names[0] = “Cutie”;
1. Homogeneous:
All elements must be of the same data type.
2. Fixed-size:
Arrays have a fixed size, which is determined at
creation time.
3. Indexed:
Elements are accessed using an index
(starting from 0).
4. Contiguous memory allocation:
Elements are stored in adjacent memory
locations.
Thank you!