![]() |
VOOZH | about |
In Java, to get the first element in an array, we can access the element at index 0 using array indexing.
Example 1: Below is a simple example that demonstrates how to access the element at index 0 in an array.
5
arrayName[0];
Example 2: Here, we are trying to access the first element in an empty array. It will throw an ArrayIndexOutOfBoundsException.
The array is empty.
Example 3: Here, we are accessing the first element in an Array of String.
Cherry