0

I don't know, if I forgot how, or I just can't figure it out how.

For example :

        Object[][] data = {
            {"id", "projectname","valueid", "value"},
        };

And this is how they should be added, but in loop:

        Object[][] data = {
            {"id", "projectname","valueid", "value"},
            {"id2", "projectname2","valueid2", "value2"},
            {"id3", "projectname3","valueid3", "value3"},
        };

And so on..

I need a tip only, like a skeleton how it should be. I tried to figure it out, but had no idea how.

Thanks!

Ervinas34
  • 133
  • 10

2 Answers2

4

You can add a new array to another array like this :

data[1] = new Object[]{"id_1", "projectname_1","valueid_1", "value_1"};
...
data[n] = new Object[]{"id_n", "projectname_n","valueid_n", "value_n"};

You can use this way in any loop for example :

int length = 5;
Object[][] data = new Object[length][];
for(int i = 0; i < length; i++){
    data[i] = new Object[]{...some information};
}
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
1
for (int i = 1; i < data.length; i++) {
    for (int j = 0; j < data[i].length; j++) {
        int line = i+1;
        data[i][j] = data[0][j]+ line;
    }
}
azro
  • 53,056
  • 7
  • 34
  • 70
Imen Gharsalli
  • 367
  • 2
  • 13