Access Array elements
- Array is automatically initializes with default values.
- Default values depend on type of array.
- We can process array elements using their index
class Demo
{
public static void main(String[] args)
{
int arr[ ] = new int[5];
System.out.println("Array elements are : " );
for (int i=0 ; i<arr.length ; i++)
{
System.out.println(arr[i]);
}
}
}
- If the array is of type String, the default value is null.
- String is a class(object).
- Object stores memory address, hence it is called pointer variable.
- Default pointer variable is null.
class Demo
{
public static void main(String[] args)
{
String arr[ ] = new String[5];
System.out.println("Array elements are : " );
for (int i=0 ; i<arr.length ; i++)
{
System.out.println(arr[i]);
}
}
}