capypad
0 day streak
java / beginner
Snippet

Declaring and Accessing Arrays

Arrays are used to store multiple values of the same type in a single variable. Elements are accessed using zero-based indexing.

snippet.java
java
1
2
3
int[] numbers = {10, 20, 30};
int firstElement = numbers[0];
numbers[1] = 50;
Breakdown
1
int[] numbers = {10, 20, 30};
Creates an array of integers with three initial values.
2
int firstElement = numbers[0];
Retrieves the value at the first position (index 0).
3
numbers[1] = 50;
Updates the second element of the array to 50.