如何以编程方式在二维数组中插入值?

vin*_*thp 8 java arrays android arraylist multidimensional-array

我想在java中动态地执行此操作.我知道如何在单维数组中插入值.我在二维数组中有点困惑.

static final String shades[][] = {


 // Shades of grey
  {
    "lightgrey", 
    "dimgray", 
    "sgi gray 92", 
  },
 // Shades of blue
  {
    "dodgerblue 2", 
    "steelblue 2", 
    "powderblue", 
  },
// Shades of yellow
  {
    "yellow 1",
    "gold 1",
    "darkgoldenrod 1", 
  },
 // Shades of red
  {
    "indianred 1", 
    "firebrick 1", 
    "maroon", 
  }
};
Run Code Online (Sandbox Code Playgroud)

Moh*_*ikh 9

String[][] shades = new String[intSize][intSize];
 // print array in rectangular form
 for (int r=0; r<shades.length; r++) {
     for (int c=0; c<shades[r].length; c++) {
         shades[r][c]="hello";//your value
     }
 }
Run Code Online (Sandbox Code Playgroud)


mar*_*rio 5

尝试下面的代码,

String[][] shades = new String[4][3];
for(int i = 0; i < 4; i++)
{
  for(int y = 0; y < 3; y++)
  {
    shades[i][y] = value;
  }
}
Run Code Online (Sandbox Code Playgroud)