Intro | Declaring, Initializing | Accessing, Updating | Traversing | Algorithms |
Unit 8 - 2D Arrays Accessing and Updating
2D Arrays Lesson
Accessing and updating the values of a 2D array
In Java, accessing and updating values in a 2D array is done using the row and column indices. The general format is:
- **Accessing a value**: array[row][column]
- **Updating a value**: array[row][column] = newValue;
Popcorn Hack 1 (Part 2)
- Update the values of the array, you made in part 1 to the group members in another group
public class Main {
public static void main(String[] args) {
// Updated group pairs with new members
String[][] groupPairs = {
{"Kayden", "Sharon"},
{"Alisha", "Anika"},
};
// Loop through the new group pairs and print them
for (String[] pair : groupPairs) {
System.out.println(pair[0] + " and " + pair[1]);
}
}
}