java / beginner
Snippet
Accessing Array Elements
Arrays store multiple values of the same type. Elements are accessed using a zero-based index.
snippet.java
1
2
3
String[] names = {"Alice", "Bob", "Charlie"};String first = names[0];System.out.println(first);
Breakdown
1
String[] names = {...}
Declares and initializes an array of Strings.
2
names[0]
Retrieves the first element of the array (index 0).