Unit 8 - 2D Arrays Accessing and Updating
2D Arrays Lesson
Unit 8 Intro
Unit 8 Declare/Initialize
Unit 8 Traversing
Unit 8 Accessing and Updating
Unit 8 Algorithms
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
String[][] people1 = {
{"Jonathan","Tarun"},
{"Srijan","Ian"}
};
people1[0][0] = "First Guy";
people1[0][1] = "Another dude";
people1[1][0] = "Another person";
people1[1][1] = "Another person again";
for(int i = 0; i < people1.length; i++) {
for (int j = 0; j < people1[i].length; j++) {
System.out.print(people1[i][j] + " ");
}
System.out.println();
}
First Guy Another dude
Another person Another person again