KEMBAR78
intorduction to Arrays in java | PDF
Arrays
An array is used to hold the more than one
number of homogeneous data.
The length of an array is established when the
array is created.
After creation, its length is fixed.
Array initialization
The syntax of array initialization is
datatype[] name={item1,item2,...,item n};
OR
name[index position]= item or value;
Accessing array elements
Array elements can be either accessed using
their index value or using the looping statements
Example
System.out.println(a[1]);
or
for(int i =0 ;some condition; i++)
{ System.out.println(a[i]);}
Array resizing
Syntax
aname=Arrays.copyOf(aname, new size);
example
int[] a= new int[4];
a= Arrays.copyOf(a, 8);
Types of array
● One dimensional array
● Two dimensional array
● Multi dimensional array
Two dimensional array
The two dimensional arrays are like a table
The Syntax for declaring a 2-D array is
Dtype [][] name= new Dtype[size][size];

intorduction to Arrays in java

  • 1.
    Arrays An array isused to hold the more than one number of homogeneous data. The length of an array is established when the array is created. After creation, its length is fixed.
  • 2.
    Array initialization The syntaxof array initialization is datatype[] name={item1,item2,...,item n}; OR name[index position]= item or value;
  • 3.
    Accessing array elements Arrayelements can be either accessed using their index value or using the looping statements Example System.out.println(a[1]); or for(int i =0 ;some condition; i++) { System.out.println(a[i]);}
  • 4.
    Array resizing Syntax aname=Arrays.copyOf(aname, newsize); example int[] a= new int[4]; a= Arrays.copyOf(a, 8);
  • 5.
    Types of array ●One dimensional array ● Two dimensional array ● Multi dimensional array
  • 6.
    Two dimensional array Thetwo dimensional arrays are like a table The Syntax for declaring a 2-D array is Dtype [][] name= new Dtype[size][size];