0% found this document useful (0 votes)
2 views12 pages

Java Arrays: Basics and Syntax Guide

The document provides an overview of Java arrays, explaining that they are collections of multiple values of the same datatype accessed via an index. It includes syntax for declaring arrays with and without initial values, as well as methods for reading and modifying array elements. Key characteristics of arrays such as being homogeneous, fixed-size, indexed, and using contiguous memory allocation are also highlighted.

Uploaded by

2sdhhtp5sd
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)
2 views12 pages

Java Arrays: Basics and Syntax Guide

The document provides an overview of Java arrays, explaining that they are collections of multiple values of the same datatype accessed via an index. It includes syntax for declaring arrays with and without initial values, as well as methods for reading and modifying array elements. Key characteristics of arrays such as being homogeneous, fixed-size, indexed, and using contiguous memory allocation are also highlighted.

Uploaded by

2sdhhtp5sd
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

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!

You might also like