Professional Documents
Culture Documents
Array
Group of contiguous or related data items that share
common name
Example:
student[5] – represent the 5th students
type arrayname [ ];
type [ ] arrayname;
Examples:
int number[ ];
float average[ ];
int [ ] count;
memory.
number=new int[5];
average=new float[10];
Creation of Arrays
We can combine first two steps as:
Statements Result
number
int number [ ];
points
nowhere
number = new int [ 2 ];
points to
number[0] int object
number[1]
Initialization of Arrays
The final step is to put values into the array created.
Number[0]=12
Number[1]=23
Subscript or index always starts with 0 and ends with a value one
int a[ ] = {1,2,3,4,5};
int b[ ];
b = a;
Array Length
In Java, all arrays store the allocated size in a variable named
length
Example:
int a [ ] = { 1, 2, 3, 4, 5 };
Example : v [ 2 ] [ 1 ]
String stringname;
stringname = new String (“Hello”);
String arrays
List. removeElementAt(n) Removes the specified nth item from the list