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

java6

Java script 6

Uploaded by

siva
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

java6

Java script 6

Uploaded by

siva
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

ment or insity Arrays

ethe sWItG An arrayisa derived data type, which can be used for storing multiple values.
If anapplication requires multiple values, then we can store those multiple values by declaring
de the lo0, multiple variables. If we declare multiple variables in a program then the code size will increase,
and readability will be reduced.
to specihyy In order to reduce the code size, and improve the readability of the code, we take the help of
arrays. Arrays in java language are classified into two types. They are
1) Single dimension array
2) Multidimension array
Single dimension array: single dimension array is a collection of multiple values represented in
the form of a single row or single column.
Syntax for declaring a single dimension array:
datatype arrayNamel]: each pair of square bracket represents one dimension.
The name of the array can be any valid java identifier
Rule 1:At the time of array declaration we can specify the pair of [] either before the array name
or after the array name.
Example:
int rollNo[]:
doublel] marks;
char [Igrade;
ne contin
boolean result[];
Rule 2: At the time of array declaration we should not specify the size of the array.
mended Syntax for Creation of single dimension Array:
datatype arrayName[] =new datatype[size];
Or
datatype arrayName[;
arrayName = new datatype[size],;
Example:
int arrl] = new int[10];
Or
int arr[);
arr=new int[10];
Kule: Specifying the size of the array at the time of array creation is mandatory and it
byte, short, int, char type only. should be of
The size of the array must be a
runtime error called positive number. If a negative number is specified, then we get a

You might also like