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;

image

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) {

        String[][] team = {
            {"Eshaan", "Arthur"},
            {"Miheer", "Saraas"},
            {"Beijan", "Hanlun"}
        };

        // Display Array Code below
        for(int i = 0; i < team.length; i++) {
            for (int j = 0; j < team[i].length; j++) {
                System.out.print(team[i][j] + " ");
            }
            System.out.println();
        }

        System.out.println("\nNew array:");

        team[0][0] = "Antonio";
        team[0][1] = "Brown";
        team[1][0] = "John";
        team[1][1] = "Billy";
        team[2][0] = "Bobby";
        team[2][1] = "Chris";

        // Display Array Code below
        for(int i = 0; i < team.length; i++) {
            for (int j = 0; j < team[i].length; j++) {
                System.out.print(team[i][j] + " ");
            }
            System.out.println();
        }
    }
}

Main.main(null)
Eshaan Arthur 
Miheer Saraas 
Beijan Hanlun 

New array:
Antonio Brown 
John Billy 
Bobby Chris