VOOZH about

URL: https://www.geeksforgeeks.org/java/how-to-get-first-element-in-array-in-java/

⇱ How to Get First Element in Array in Java? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Get First Element in Array in Java?

Last Updated : 23 Jul, 2025

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.


Output
5

Syntax

arrayName[0];

  • arrayName: The name of the array.
  • [0]: The index of the first element in the array.

Example 2: Here, we are trying to access the first element in an empty array. It will throw an ArrayIndexOutOfBoundsException.


Output
The array is empty.


Example 3: Here, we are accessing the first element in an Array of String.


Output
 Cherry
Comment
Article Tags: