0% found this document useful (0 votes)
13 views

Arraygroup 2 Edited

It resources
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)
13 views

Arraygroup 2 Edited

It resources
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/ 13

Java

Arrays
Array
Arrays are used to store multiple values in a
single variable, instead of declaring separate
variables for each value.

Array in java is index-based, the first element of


the array is stored at 0th position, the second
element at 1st position, and so on.
How to Declare
Array

dataType – it can be primitive data types or java objects.

var-name or ArrayName – it is identifier.


Two Ways to Create
Array
We can declare and store the values directly at the time of
declaration :
int marks[ ] = { 90, 97, 95, 99, 100 };

The second way of creating an array is by first declaring the


array and then allocating the memory through the new keyword :
int[] Number = new int[10];
Single
Dimensional
Java
Arrays
Definition
A single dimensional array in Java is an array that
holds a sequence of elements, all of the same type,
accessed through an index.
Function:
Store same type elements: Single dimensional arrays permit you to
reserve memory locations to store elements of the same types.

Access elements using indices: It's easy to access these elements


using indices which start at 0.

Code readability: They help in organizing data in a linear manner,


thereby enhancing readability.
Anatomy

Index 0 1 2 3 4 5
Eleme 1 2 3 4 5 6
nt
Initialization
• Initialization means giving values to the array created.
• The values are determined by braces and separated by commas.

Example:

int[] num = {1,2,3,4,5,6,7,8,9,0};

String[] colors = {“red”, “blue” , “yellow” , “orange”};


Sample Code
Double
Dimensional
Java
Arrays
Definition
Two – dimensional array is the simplest form of a
multidimensional array. A two – dimensional array can be
seen as an array of one – dimensional array for easier
understanding.
Sample Code

You might also like