It is a collection of similar data type elements and all element of array are stored sequentially
and addressed using a single variable name. Array is declared by defining the variable type with
square brackets and elements of an array access using index.
Program to Access Array Elements |
Output |
public class MyClass
{
public static void main(String[] args)
{
int[] nos = new int[]{ 1,2,3,4,5,6,7,8,9,10 };
System.out.println(nos[0]);
}
}
|
1 |
Program to change Array Elements |
Output |
public class numbersprint {
public static void main(String[] args) {
int[] nos = new int[]{ 1,2,3,4,5,6,7,8,9,10 };
nos [0] = 10;
System.out.println(nos [0]);
System.out.println("Array Length:"+nos.length);
}
}
|
10,Array Length:10 |
Multidimensional Arrays
It is an array containing one or more arrays or array with index.
Program on Multidimensional Arrays |
Output |
public class numbersprint
{
public static void main(String[] args)
{
int[][]nos = { {1, 3, 5}, {2, 4, 6},{1, 3, 5} };
int no1= nos [2][2];
System.out.println(no1);
}
}
|
4 |
|