0% found this document useful (0 votes)
9 views10 pages

Arrays

Uploaded by

revathi
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)
9 views10 pages

Arrays

Uploaded by

revathi
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/ 10

Arrays

S.REVATHI AP/CSE
Arrays in Java

An array is a group of like-typed variables that are referred to by a


common name.
Arrays in Java work differently than they do in C/C++
A Java array variable can also be declared like other variables with [ ]
The variables in the array are ordered and each have an index
beginning from 0.
The size of an array must be specified by an int or short value and not
long.
Example
Types

1.One-Dimensional Arrays
2.Two-Dimensional or Multi-Dimensional Arrays
1.One-Dimensional Arrays :
The general form of a one-dimensional array declaration is:

data type var-name [ ];

Create an array of primitive data types like char, float, double, etc. or user-
defined data types (objects of a class).

Thus, the element type for the array determines what type of data the array will
hold.

Instantiating an Array:

var-name = new type [size];


Declaration and Initialization

Example:

int intArray[]; //declaring array

intArray = new int[20]; // allocating memory to array

CODING DEMO
2.Multidimensional Arrays

Multidimensional Arrays can be defined as array of arrays.


Data in multidimensional arrays are stored in tabular form (in
row major order).

Syntax:
data_type[1st dimension][2nd dimension][]..[Nthdimension] array_name = new data_type[size1][size2]….
[sizeN];
Example
Two dimensional array:

int twoD_arr [] [] = new int[10][20];

Three dimensional array:

int threeD_arr [] [] []= new int[10][20][30];


Conceptual View
CODING DEMO

You might also like